using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using UniRx.InternalUtil;
using UniRx.Operators;
namespace UniRx
{
// Standard Query Operators
// onNext implementation guide. enclose otherFunc but onNext is not catch.
// try{ otherFunc(); } catch { onError() }
// onNext();
public static partial class Observable
{
static readonly TimeSpan InfiniteTimeSpan = new TimeSpan(0, 0, 0, 0, -1); // from .NET 4.5
public static IObservable
Select(this IObservable source, Func selector)
{
// sometimes cause "which no ahead of time (AOT) code was generated." on IL2CPP...
//var select = source as ISelect;
//if (select != null)
//{
// return select.CombineSelector(selector);
//}
// optimized path
var whereObservable = source as UniRx.Operators.WhereObservable;
if (whereObservable != null)
{
return whereObservable.CombineSelector(selector);
}
return new SelectObservable(source, selector);
}
public static IObservable Select(this IObservable source, Func selector)
{
return new SelectObservable(source, selector);
}
public static IObservable Where(this IObservable source, Func predicate)
{
// optimized path
var whereObservable = source as UniRx.Operators.WhereObservable;
if (whereObservable != null)
{
return whereObservable.CombinePredicate(predicate);
}
var selectObservable = source as UniRx.Operators.ISelect;
if (selectObservable != null)
{
return selectObservable.CombinePredicate(predicate);
}
return new WhereObservable(source, predicate);
}
public static IObservable Where(this IObservable source, Func predicate)
{
return new WhereObservable(source, predicate);
}
///
/// Lightweight SelectMany for Single Async Operation.
///
public static IObservable ContinueWith(this IObservable source, IObservable other)
{
return ContinueWith(source, _ => other);
}
///
/// Lightweight SelectMany for Single Async Operation.
///
public static IObservable
ContinueWith(this IObservable source, Func> selector)
{
return new ContinueWithObservable(source, selector);
}
public static IObservable SelectMany(this IObservable source, IObservable other)
{
return SelectMany(source, _ => other);
}
public static IObservable
SelectMany(this IObservable source, Func> selector)
{
return new SelectManyObservable(source, selector);
}
public static IObservable SelectMany(this IObservable source, Func> selector)
{
return new SelectManyObservable(source, selector);
}
public static IObservable SelectMany(this IObservable source, Func> collectionSelector, Func resultSelector)
{
return new SelectManyObservable(source, collectionSelector, resultSelector);
}
public static IObservable SelectMany(this IObservable source, Func> collectionSelector, Func resultSelector)
{
return new SelectManyObservable(source, collectionSelector, resultSelector);
}
public static IObservable SelectMany(this IObservable source, Func> selector)
{
return new SelectManyObservable(source, selector);
}
public static IObservable SelectMany(this IObservable source, Func> selector)
{
return new SelectManyObservable(source, selector);
}
public static IObservable SelectMany(this IObservable source, Func> collectionSelector, Func resultSelector)
{
return new SelectManyObservable(source, collectionSelector, resultSelector);
}
public static IObservable SelectMany(this IObservable source, Func> collectionSelector, Func resultSelector)
{
return new SelectManyObservable(source, collectionSelector, resultSelector);
}
public static IObservable ToArray(this IObservable source)
{
return new ToArrayObservable(source);
}
public static IObservable> ToList(this IObservable source)
{
return new ToListObservable(source);
}
public static IObservable Do(this IObservable source, IObserver observer)
{
return new DoObserverObservable(source, observer);
}
public static IObservable Do(this IObservable source, Action onNext)
{
return new DoObservable(source, onNext, Stubs.Throw, Stubs.Nop);
}
public static IObservable Do(this IObservable source, Action onNext, Action onError)
{
return new DoObservable(source, onNext, onError, Stubs.Nop);
}
public static IObservable Do(this IObservable source, Action onNext, Action onCompleted)
{
return new DoObservable(source, onNext, Stubs.Throw, onCompleted);
}
public static IObservable Do(this IObservable source, Action onNext, Action onError, Action onCompleted)
{
return new DoObservable(source, onNext, onError, onCompleted);
}
public static IObservable DoOnError(this IObservable source, Action onError)
{
return new DoOnErrorObservable(source, onError);
}
public static IObservable DoOnCompleted(this IObservable source, Action onCompleted)
{
return new DoOnCompletedObservable(source, onCompleted);
}
public static IObservable DoOnTerminate(this IObservable source, Action onTerminate)
{
return new DoOnTerminateObservable(source, onTerminate);
}
public static IObservable DoOnSubscribe(this IObservable source, Action onSubscribe)
{
return new DoOnSubscribeObservable(source, onSubscribe);
}
public static IObservable DoOnCancel(this IObservable source, Action onCancel)
{
return new DoOnCancelObservable(source, onCancel);
}
public static IObservable> Materialize(this IObservable source)
{
return new MaterializeObservable(source);
}
public static IObservable Dematerialize(this IObservable> source)
{
return new DematerializeObservable(source);
}
public static IObservable DefaultIfEmpty(this IObservable source)
{
return new DefaultIfEmptyObservable(source, default(T));
}
public static IObservable DefaultIfEmpty(this IObservable source, T defaultValue)
{
return new DefaultIfEmptyObservable(source, defaultValue);
}
public static IObservable Distinct(this IObservable source)
{
#if !UniRxLibrary
var comparer = UnityEqualityComparer.GetDefault();
#else
var comparer = EqualityComparer.Default;
#endif
return new DistinctObservable(source, comparer);
}
public static IObservable Distinct(this IObservable source, IEqualityComparer comparer)
{
return new DistinctObservable(source, comparer);
}
public static IObservable Distinct(this IObservable source, Func keySelector)
{
#if !UniRxLibrary
var comparer = UnityEqualityComparer.GetDefault();
#else
var comparer = EqualityComparer.Default;
#endif
return new DistinctObservable(source, keySelector, comparer);
}
public static IObservable Distinct(this IObservable source, Func keySelector, IEqualityComparer comparer)
{
return new DistinctObservable(source, keySelector, comparer);
}
public static IObservable DistinctUntilChanged(this IObservable source)
{
#if !UniRxLibrary
var comparer = UnityEqualityComparer.GetDefault();
#else
var comparer = EqualityComparer.Default;
#endif
return new DistinctUntilChangedObservable(source, comparer);
}
public static IObservable DistinctUntilChanged(this IObservable source, IEqualityComparer comparer)
{
if (source == null) throw new ArgumentNullException("source");
return new DistinctUntilChangedObservable(source, comparer);
}
public static IObservable DistinctUntilChanged(this IObservable source, Func keySelector)
{
#if !UniRxLibrary
var comparer = UnityEqualityComparer.GetDefault();
#else
var comparer = EqualityComparer.Default;
#endif
return new DistinctUntilChangedObservable(source, keySelector, comparer);
}
public static IObservable DistinctUntilChanged(this IObservable source, Func keySelector, IEqualityComparer comparer)
{
if (source == null) throw new ArgumentNullException("source");
return new DistinctUntilChangedObservable(source, keySelector, comparer);
}
public static IObservable IgnoreElements(this IObservable source)
{
return new IgnoreElementsObservable(source);
}
public static IObservable ForEachAsync(this IObservable source, Action onNext)
{
return new ForEachAsyncObservable(source, onNext);
}
public static IObservable ForEachAsync(this IObservable source, Action onNext)
{
return new ForEachAsyncObservable(source, onNext);
}
}
}