Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Use the common method names in Rx.Net instead of using the LINQ ones.
using System.Collections.Generic;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace System.Reactive.ApiMappings
{
public static class ObservableEx
{
public static IObservable<TResult> Just<TResult>(TResult value)
=> Observable.Return(value);
public static IObservable<TResult> Just<TResult>(TResult value, IScheduler scheduler)
=> Observable.Return(value, scheduler);
public static IObservable<TResult> FlatMap<TSource, TResult>(this IObservable<TSource> source, Func<TSource, IObservable<TResult>> onNext, Func<Exception, IObservable<TResult>> onError, Func<IObservable<TResult>> onCompleted)
=> source.SelectMany(onNext, onError, onCompleted);
public static IObservable<TResult> FlatMap<TSource, TResult>(this IObservable<TSource> source, Func<TSource, int, Task<TResult>> selector)
=> source.SelectMany(selector);
public static IObservable<TResult> FlatMap<TSource, TResult>(this IObservable<TSource> source, Func<TSource, CancellationToken, Task<TResult>> selector)
=> source.SelectMany(selector);
public static IObservable<TResult> FlatMap<TSource, TResult>(this IObservable<TSource> source, Func<TSource, int, IObservable<TResult>> onNext, Func<Exception, IObservable<TResult>> onError, Func<IObservable<TResult>> onCompleted)
=> source.SelectMany(onNext, onError, onCompleted);
public static IObservable<TResult> FlatMap<TSource, TCollection, TResult>(this IObservable<TSource> source, Func<TSource, int, IEnumerable<TCollection>> collectionSelector, Func<TSource, int, TCollection, int, TResult> resultSelector)
=> source.SelectMany(collectionSelector, resultSelector);
public static IObservable<TResult> FlatMap<TSource, TCollection, TResult>(this IObservable<TSource> source, Func<TSource, int, IObservable<TCollection>> collectionSelector, Func<TSource, int, TCollection, int, TResult> resultSelector)
=> source.SelectMany(collectionSelector, resultSelector);
public static IObservable<TResult> FlatMap<TSource, TTaskResult, TResult>(this IObservable<TSource> source, Func<TSource, int, CancellationToken, Task<TTaskResult>> taskSelector, Func<TSource, int, TTaskResult, TResult> resultSelector)
=> source.SelectMany(taskSelector, resultSelector);
public static IObservable<TResult> FlatMap<TSource, TCollection, TResult>(this IObservable<TSource> source, Func<TSource, IEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector)
=> source.SelectMany(collectionSelector, resultSelector);
public static IObservable<TResult> FlatMap<TSource, TResult>(this IObservable<TSource> source, Func<TSource, int, IEnumerable<TResult>> selector)
=> source.SelectMany(selector);
public static IObservable<TResult> FlatMap<TSource, TResult>(this IObservable<TSource> source, Func<TSource, int, CancellationToken, Task<TResult>> selector)
=> source.SelectMany(selector);
public static IObservable<TResult> FlatMap<TSource, TCollection, TResult>(this IObservable<TSource> source, Func<TSource, IObservable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector)
=> source.SelectMany(collectionSelector, resultSelector);
public static IObservable<TResult> FlatMap<TSource, TResult>(this IObservable<TSource> source, Func<TSource, Task<TResult>> selector)
=> source.SelectMany(selector);
public static IObservable<TResult> FlatMap<TSource, TTaskResult, TResult>(this IObservable<TSource> source, Func<TSource, int, Task<TTaskResult>> taskSelector, Func<TSource, int, TTaskResult, TResult> resultSelector)
=> source.SelectMany(taskSelector, resultSelector);
public static IObservable<TResult> FlatMap<TSource, TResult>(this IObservable<TSource> source, Func<TSource, IEnumerable<TResult>> selector)
=> source.SelectMany(selector);
public static IObservable<TResult> FlatMap<TSource, TTaskResult, TResult>(this IObservable<TSource> source, Func<TSource, Task<TTaskResult>> taskSelector, Func<TSource, TTaskResult, TResult> resultSelector)
=> source.SelectMany(taskSelector, resultSelector);
public static IObservable<TResult> FlatMap<TSource, TTaskResult, TResult>(this IObservable<TSource> source, Func<TSource, CancellationToken, Task<TTaskResult>> taskSelector, Func<TSource, TTaskResult, TResult> resultSelector)
=> source.SelectMany(taskSelector, resultSelector);
public static IObservable<TResult> FlatMap<TSource, TResult>(this IObservable<TSource> source, Func<TSource, int, IObservable<TResult>> selector)
=> source.SelectMany(selector);
public static IObservable<TResult> FlatMap<TSource, TResult>(this IObservable<TSource> source, Func<TSource, IObservable<TResult>> selector)
=> source.SelectMany(selector);
public static IObservable<TOther> FlatMap<TSource, TOther> (this IObservable<TSource> source, IObservable<TOther> other)
=> source.SelectMany(other);
public static IObservable<TResult> Map<TSource, TResult> (this IObservable<TSource> source, Func<TSource, TResult> selector)
=> source.Select(selector);
public static IObservable<TResult> Map<TSource, TResult> (this IObservable<TSource> source, Func<TSource, int, TResult> selector)
=> source.Select(selector);
public static IObservable<TSource> Debounce<TSource, TThrottle> (this IObservable<TSource> source, Func<TSource, IObservable<TThrottle>> throttleDurationSelector)
=> source.Throttle(throttleDurationSelector);
public static IObservable<TSource> Debounce<TSource> (this IObservable<TSource> source, TimeSpan dueTime)
=> source.Throttle(dueTime);
public static IObservable<TSource> Debounce<TSource> (this IObservable<TSource> source, TimeSpan dueTime, IScheduler scheduler)
=> source.Throttle(dueTime, scheduler);
public static IObservable<TSource> Filter<TSource> (this IObservable<TSource> source, Func<TSource, bool> predicate)
=> source.Where(predicate);
public static IObservable<TSource> Filter<TSource> (this IObservable<TSource> source, Func<TSource, int, bool> predicate)
=> source.Where(predicate);
public static IObservable<TSource> Serialize<TSource> (this IObservable<TSource> source, object gate)
=> source.Synchronize(gate);
public static IObservable<TSource> Serialize<TSource> (this IObservable<TSource> source)
=> source.Synchronize();
public static IObservable<TAccumulate> Reduce<TSource, TAccumulate> (this IObservable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> accumulator)
=> source.Aggregate(seed, accumulator);
public static IObservable<TResult> Reduce<TSource, TAccumulate, TResult> (this IObservable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> accumulator, Func<TAccumulate, TResult> resultSelector)
=> source.Aggregate(seed, accumulator, resultSelector);
public static IObservable<TSource> Reduce<TSource> (this IObservable<TSource> source, Func<TSource, TSource, TSource> accumulator)
=> source.Aggregate(accumulator);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment