Class ReactiveExtensions
- Namespace
- ReactiveUI.Extensions
- Assembly
- ReactiveUI.Extensions.dll
Extension methods for System.Reactive.
public static class ReactiveExtensions
- Inheritance
-
ReactiveExtensions
Methods
AsSignal<T>(IObservable<T>)
Change the source observable type to System.Reactive.Unit. This allows us to be notified when the observable emits a value.
public static IObservable<Unit> AsSignal<T>(this IObservable<T> observable)
Parameters
observableIObservable<T>The observable to convert.
Returns
- IObservable<Unit>
The signal.
Type Parameters
TThe current type of the observable.
BufferUntil(IObservable<char>, char, char)
Buffers until Start char and End char are found.
public static IObservable<string> BufferUntil(this IObservable<char> @this, char startsWith, char endsWith)
Parameters
thisIObservable<char>The source observable of characters.
startsWithcharThe starting delimiter.
endsWithcharThe ending delimiter.
Returns
- IObservable<string>
A sequence of buffered strings including the start and end delimiters.
BufferUntilIdle<T>(IObservable<T>, TimeSpan, IScheduler?)
Emit a batch when the stream goes quiet.
public static IObservable<IList<T>> BufferUntilIdle<T>(this IObservable<T> source, TimeSpan idleTime, IScheduler? scheduler = null)
Parameters
sourceIObservable<T>The source.
idleTimeTimeSpanThe idle time.
schedulerISchedulerThe scheduler.
Returns
- IObservable<IList<T>>
A sequence of buffered lists.
Type Parameters
TThe type of the elements in the source sequence.
BufferUntilInactive<T>(IObservable<T>, TimeSpan, IScheduler?)
Buffers items until inactivity period elapses then emits and resets buffer.
public static IObservable<IList<T>> BufferUntilInactive<T>(this IObservable<T> source, TimeSpan inactivityPeriod, IScheduler? scheduler = null)
Parameters
sourceIObservable<T>Source sequence.
inactivityPeriodTimeSpanInactivity period.
schedulerISchedulerScheduler.
Returns
- IObservable<IList<T>>
Sequence of buffered lists.
Type Parameters
TElement type.
CatchAndReturn<T>(IObservable<T>, T)
Catches any error and returns a fallback value then completes.
public static IObservable<T> CatchAndReturn<T>(this IObservable<T> source, T fallback)
Parameters
sourceIObservable<T>Source sequence.
fallbackTFallback value.
Returns
- IObservable<T>
Sequence producing either original values or fallback on error then completing.
Type Parameters
TElement type.
CatchAndReturn<T, TException>(IObservable<T>, Func<TException, T>)
Catches a specific exception type mapping it to a fallback value.
public static IObservable<T> CatchAndReturn<T, TException>(this IObservable<T> source, Func<TException, T> fallbackFactory) where TException : Exception
Parameters
sourceIObservable<T>Source sequence.
fallbackFactoryFunc<TException, T>Factory producing fallback from the exception.
Returns
- IObservable<T>
Recovered sequence.
Type Parameters
TElement type.
TExceptionException type.
CatchIgnore<TSource>(IObservable<TSource?>)
Catch exception and return Observable.Empty.
public static IObservable<TSource?> CatchIgnore<TSource>(this IObservable<TSource?> source)
Parameters
sourceIObservable<TSource>The source.
Returns
- IObservable<TSource>
A sequence that ignores errors and completes.
Type Parameters
TSourceThe type of the source.
CatchIgnore<TSource, TException>(IObservable<TSource>, Action<TException>)
Catch exception and return Observable.Empty.
public static IObservable<TSource> CatchIgnore<TSource, TException>(this IObservable<TSource> source, Action<TException> errorAction) where TException : Exception
Parameters
sourceIObservable<TSource>The source.
errorActionAction<TException>The error action.
Returns
- IObservable<TSource>
A sequence that invokes
errorActionon error and completes.
Type Parameters
TSourceThe type of the source.
TExceptionThe type of the exception.
CombineLatestValuesAreAllFalse(IEnumerable<IObservable<bool>>)
Latest values of each sequence are all false.
public static IObservable<bool> CombineLatestValuesAreAllFalse(this IEnumerable<IObservable<bool>> sources)
Parameters
sourcesIEnumerable<IObservable<bool>>The sources.
Returns
- IObservable<bool>
A sequence that emits true when all latest booleans are false.
CombineLatestValuesAreAllTrue(IEnumerable<IObservable<bool>>)
Latest values of each sequence are all true.
public static IObservable<bool> CombineLatestValuesAreAllTrue(this IEnumerable<IObservable<bool>> sources)
Parameters
sourcesIEnumerable<IObservable<bool>>The sources.
Returns
- IObservable<bool>
A sequence that emits true when all latest booleans are true.
Conflate<T>(IObservable<T>, TimeSpan, IScheduler)
Applies a conflation algorithm to an observable stream. Anytime the stream OnNext twice below minimumUpdatePeriod, the second update gets delayed to respect the minimumUpdatePeriod. If more than 2 updates happen, only the last update is pushed.
public static IObservable<T> Conflate<T>(this IObservable<T> source, TimeSpan minimumUpdatePeriod, IScheduler scheduler)
Parameters
sourceIObservable<T>The stream.
minimumUpdatePeriodTimeSpanMinimum delay between two updates.
schedulerISchedulerScheduler to publish updates.
Returns
- IObservable<T>
The conflated stream.
Type Parameters
TThe type.
DebounceImmediate<T>(IObservable<T>, TimeSpan, IScheduler?)
Debounces with an immediate first emission then standard debounce behavior.
public static IObservable<T> DebounceImmediate<T>(this IObservable<T> source, TimeSpan dueTime, IScheduler? scheduler = null)
Parameters
sourceIObservable<T>Source sequence.
dueTimeTimeSpanDebounce time.
schedulerISchedulerScheduler (optional).
Returns
- IObservable<T>
Debounced sequence.
Type Parameters
TElement type.
DebounceUntil<T>(IObservable<T>, TimeSpan, Func<T, bool>)
Debounce until a condition becomes true.
public static IObservable<T> DebounceUntil<T>(this IObservable<T> source, TimeSpan debounce, Func<T, bool> condition)
Parameters
sourceIObservable<T>The source.
debounceTimeSpanThe debounce.
conditionFunc<T, bool>The condition.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
DebounceUntil<T>(IObservable<T>, TimeSpan, Func<T, bool>, IScheduler)
Debounce until a condition becomes true.
public static IObservable<T> DebounceUntil<T>(this IObservable<T> source, TimeSpan debounce, Func<T, bool> condition, IScheduler scheduler)
Parameters
sourceIObservable<T>The source.
debounceTimeSpanThe debounce.
conditionFunc<T, bool>The condition.
schedulerISchedulerThe scheduler for the delay.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
DetectStale<T>(IObservable<T>, TimeSpan, IScheduler)
Detects when a stream becomes inactive for some period of time.
public static IObservable<IStale<T>> DetectStale<T>(this IObservable<T> source, TimeSpan stalenessPeriod, IScheduler scheduler)
Parameters
sourceIObservable<T>source stream.
stalenessPeriodTimeSpanIf source stream does not OnNext any update during this period, it is declared stale.
schedulerISchedulerThe scheduler.
Returns
- IObservable<IStale<T>>
Observable stale markers or updates.
Type Parameters
Tupdate type.
DoOnDispose<T>(IObservable<T>, Action)
Executes an action when subscription is disposed.
public static IObservable<T> DoOnDispose<T>(this IObservable<T> source, Action disposeAction)
Parameters
sourceIObservable<T>Source sequence.
disposeActionActionAction to run on dispose.
Returns
- IObservable<T>
Original sequence with dispose side-effect.
Type Parameters
TElement type.
DoOnSubscribe<T>(IObservable<T>, Action)
Executes an action at subscription time.
public static IObservable<T> DoOnSubscribe<T>(this IObservable<T> source, Action action)
Parameters
sourceIObservable<T>Source sequence.
actionActionAction to run on subscribe.
Returns
- IObservable<T>
Original sequence with subscribe side-effect.
Type Parameters
TElement type.
DropIfBusy<T>(IObservable<T>, Func<T, Task>)
Drop values when the previous async operation is still running.
public static IObservable<T> DropIfBusy<T>(this IObservable<T> source, Func<T, Task> asyncAction)
Parameters
sourceIObservable<T>The source.
asyncActionFunc<T, Task>The asynchronous action.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
Filter(IObservable<string>, string)
Filters strings by regex.
public static IObservable<string> Filter(this IObservable<string> source, string regexPattern)
Parameters
sourceIObservable<string>Source sequence.
regexPatternstringRegex pattern.
Returns
- IObservable<string>
Filtered sequence.
ForEach<T>(IObservable<IEnumerable<T>>, IScheduler?)
Flattens a sequence of enumerables into individual values.
public static IObservable<T> ForEach<T>(this IObservable<IEnumerable<T>> source, IScheduler? scheduler = null)
Parameters
sourceIObservable<IEnumerable<T>>Source of enumerables.
schedulerISchedulerScheduler (optional).
Returns
- IObservable<T>
A flattened observable.
Type Parameters
TElement type.
FromArray<T>(IEnumerable<T>, IScheduler?)
Emits each element of an IEnumerable.
public static IObservable<T> FromArray<T>(this IEnumerable<T> source, IScheduler? scheduler = null)
Parameters
sourceIEnumerable<T>Source enumerable.
schedulerISchedulerScheduler (optional).
Returns
- IObservable<T>
Observable of elements.
Type Parameters
TElement type.
GetMax<T>(IObservable<T>, params IObservable<T>[])
Gets the maximum from all sources.
public static IObservable<T> GetMax<T>(this IObservable<T> @this, params IObservable<T>[] sources) where T : struct
Parameters
thisIObservable<T>The first observable.
sourcesIObservable<T>[]Other sources.
Returns
- IObservable<T>
A sequence emitting the maximum of the latest values.
Type Parameters
TThe Value Type.
GetMin<T>(IObservable<T>, params IObservable<T>[])
Gets the minimum from all sources.
public static IObservable<T> GetMin<T>(this IObservable<T> @this, params IObservable<T>[] sources) where T : struct
Parameters
thisIObservable<T>The first observable.
sourcesIObservable<T>[]Other sources.
Returns
- IObservable<T>
A sequence emitting the minimum of the latest values.
Type Parameters
TThe Value Type.
Heartbeat<T>(IObservable<T>, TimeSpan, IScheduler)
Injects heartbeats in a stream when the source stream becomes quiet.
public static IObservable<IHeartbeat<T>> Heartbeat<T>(this IObservable<T> source, TimeSpan heartbeatPeriod, IScheduler scheduler)
Parameters
sourceIObservable<T>Source stream.
heartbeatPeriodTimeSpanPeriod between heartbeats.
schedulerISchedulerScheduler.
Returns
- IObservable<IHeartbeat<T>>
Observable heartbeat values.
Type Parameters
TUpdate type.
LatestOrDefault<T>(IObservable<T>, T)
Emit the latest value or a default if none exists.
public static IObservable<T> LatestOrDefault<T>(this IObservable<T> source, T defaultValue)
Parameters
sourceIObservable<T>The source.
defaultValueTThe default value.
Returns
- IObservable<T>
A sequence that emits the latest value or the default.
Type Parameters
TThe type of the source.
LogErrors<T>(IObservable<T>, Action<Exception>)
Logs the errors. Inline error logging without terminating the stream.
public static IObservable<T> LogErrors<T>(this IObservable<T> source, Action<Exception> logger)
Parameters
sourceIObservable<T>The source.
loggerAction<Exception>The logger.
Returns
- IObservable<T>
A sequence that logs errors.
Type Parameters
TThe type of the source.
Not(IObservable<bool>)
Emits the boolean negation of the source sequence.
public static IObservable<bool> Not(this IObservable<bool> source)
Parameters
sourceIObservable<bool>Boolean source.
Returns
- IObservable<bool>
Negated boolean sequence.
ObserveOnIf<T>(IObservable<T>, bool, IScheduler)
Conditionally switch schedulers.
public static IObservable<T> ObserveOnIf<T>(this IObservable<T> source, bool condition, IScheduler scheduler)
Parameters
sourceIObservable<T>The source.
conditionboolif set to
true[condition].schedulerISchedulerThe scheduler.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
ObserveOnIf<T>(IObservable<T>, bool, IScheduler, IScheduler)
Conditionally switch schedulers.
public static IObservable<T> ObserveOnIf<T>(this IObservable<T> source, bool condition, IScheduler trueScheduler, IScheduler falseScheduler)
Parameters
sourceIObservable<T>The source.
conditionboolif set to
true[condition].trueSchedulerISchedulerThe true scheduler.
falseSchedulerISchedulerThe false scheduler.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
ObserveOnIf<T>(IObservable<T>, IObservable<bool>, IScheduler)
Conditionally switch schedulers based on a reactive condition.
public static IObservable<T> ObserveOnIf<T>(this IObservable<T> source, IObservable<bool> condition, IScheduler scheduler)
Parameters
sourceIObservable<T>The source.
conditionIObservable<bool>The reactive condition.
schedulerISchedulerThe scheduler to use when condition is true.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
ObserveOnIf<T>(IObservable<T>, IObservable<bool>, IScheduler, IScheduler)
Conditionally switch schedulers based on a reactive condition.
public static IObservable<T> ObserveOnIf<T>(this IObservable<T> source, IObservable<bool> condition, IScheduler trueScheduler, IScheduler falseScheduler)
Parameters
sourceIObservable<T>The source.
conditionIObservable<bool>The reactive condition.
trueSchedulerISchedulerThe scheduler to use when condition is true.
falseSchedulerISchedulerThe scheduler to use when condition is false.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
ObserveOnSafe<TSource>(IObservable<TSource>, IScheduler?)
If the scheduler is not null observes on that scheduler.
public static IObservable<TSource> ObserveOnSafe<TSource>(this IObservable<TSource> source, IScheduler? scheduler)
Parameters
sourceIObservable<TSource>Source sequence.
schedulerISchedulerScheduler to notify observers on (optional).
Returns
- IObservable<TSource>
The source sequence whose callbacks happen on the specified scheduler.
Type Parameters
TSourceElement type.
OnErrorRetry<TSource>(IObservable<TSource>)
Repeats the source until it terminates successfully (alias of Retry).
public static IObservable<TSource> OnErrorRetry<TSource>(this IObservable<TSource> source)
Parameters
sourceIObservable<TSource>Source sequence.
Returns
- IObservable<TSource>
Retried sequence.
Type Parameters
TSourceElement type.
OnErrorRetry<TSource, TException>(IObservable<TSource>, Action<TException>)
When caught exception, do onError action and repeat observable sequence.
public static IObservable<TSource> OnErrorRetry<TSource, TException>(this IObservable<TSource> source, Action<TException> onError) where TException : Exception
Parameters
sourceIObservable<TSource>The source.
onErrorAction<TException>The on error.
Returns
- IObservable<TSource>
A sequence that retries on error with optional delay.
Type Parameters
TSourceThe type of the source.
TExceptionThe type of the exception.
OnErrorRetry<TSource, TException>(IObservable<TSource>, Action<TException>, int)
When caught exception, do onError action and repeat observable sequence during within retryCount.
public static IObservable<TSource> OnErrorRetry<TSource, TException>(this IObservable<TSource> source, Action<TException> onError, int retryCount) where TException : Exception
Parameters
sourceIObservable<TSource>The source.
onErrorAction<TException>The on error.
retryCountintThe retry count.
Returns
- IObservable<TSource>
A sequence that retries on error with optional delay.
Type Parameters
TSourceThe type of the source.
TExceptionThe type of the exception.
OnErrorRetry<TSource, TException>(IObservable<TSource>, Action<TException>, int, TimeSpan)
When caught exception, do onError action and repeat observable sequence after delay time during within retryCount.
public static IObservable<TSource> OnErrorRetry<TSource, TException>(this IObservable<TSource> source, Action<TException> onError, int retryCount, TimeSpan delay) where TException : Exception
Parameters
sourceIObservable<TSource>The source.
onErrorAction<TException>The on error.
retryCountintThe retry count.
delayTimeSpanThe delay.
Returns
- IObservable<TSource>
A sequence that retries on error with optional delay.
Type Parameters
TSourceThe type of the source.
TExceptionThe type of the exception.
OnErrorRetry<TSource, TException>(IObservable<TSource>, Action<TException>, int, TimeSpan, IScheduler)
When caught exception, do onError action and repeat observable sequence after delay time(work on delayScheduler) during within retryCount.
public static IObservable<TSource> OnErrorRetry<TSource, TException>(this IObservable<TSource> source, Action<TException> onError, int retryCount, TimeSpan delay, IScheduler delayScheduler) where TException : Exception
Parameters
sourceIObservable<TSource>The source.
onErrorAction<TException>The on error.
retryCountintThe retry count.
delayTimeSpanThe delay.
delaySchedulerISchedulerThe delay scheduler.
Returns
- IObservable<TSource>
A sequence that retries on error with optional delay.
Type Parameters
TSourceThe type of the source.
TExceptionThe type of the exception.
OnErrorRetry<TSource, TException>(IObservable<TSource>, Action<TException>, TimeSpan)
When caught exception, do onError action and repeat observable sequence after delay time.
public static IObservable<TSource> OnErrorRetry<TSource, TException>(this IObservable<TSource> source, Action<TException> onError, TimeSpan delay) where TException : Exception
Parameters
sourceIObservable<TSource>The source.
onErrorAction<TException>The on error.
delayTimeSpanThe delay.
Returns
- IObservable<TSource>
A sequence that retries on error with optional delay.
Type Parameters
TSourceThe type of the source.
TExceptionThe type of the exception.
OnNext<T>(IObserver<T>, params T[])
Pushes multiple values to an observer.
public static void OnNext<T>(this IObserver<T> observer, params T[] events)
Parameters
observerIObserver<T>Observer to push to.
eventsT[]Values to push.
Type Parameters
TType of value.
Pairwise<T>(IObservable<T>)
Emit (previous, current) pairs.
public static IObservable<(T Previous, T Current)> Pairwise<T>(this IObservable<T> source)
Parameters
sourceIObservable<T>The source.
Returns
- IObservable<(T Previous, T Current)>
An IObservable of (T Previous, T Current).
Type Parameters
TThe type.
Partition<T>(IObservable<T>, Func<T, bool>)
Partitions a sequence into two based on predicate.
public static (IObservable<T> True, IObservable<T> False) Partition<T>(this IObservable<T> source, Func<T, bool> predicate)
Parameters
sourceIObservable<T>Source sequence.
predicateFunc<T, bool>Predicate.
Returns
- (IObservable<T> True, IObservable<T> False)
Tuple of (trueSequence, falseSequence).
Type Parameters
TElement type.
ReplayLastOnSubscribe<T>(IObservable<T>, T)
Always replay the last value, even if the source hasnÂ’t produced one yet.
public static IObservable<T> ReplayLastOnSubscribe<T>(this IObservable<T> source, T initialValue)
Parameters
sourceIObservable<T>The source.
initialValueTThe initial value.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
RetryForeverWithDelay<T>(IObservable<T>, TimeSpan)
Retries the forever with delay.
public static IObservable<T> RetryForeverWithDelay<T>(this IObservable<T> source, TimeSpan delay)
Parameters
sourceIObservable<T>The source.
delayTimeSpanThe delay.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
RetryWithBackoff<T>(IObservable<T>, int, TimeSpan, double, TimeSpan?, IScheduler?)
Retries with exponential backoff.
public static IObservable<T> RetryWithBackoff<T>(this IObservable<T> source, int maxRetries, TimeSpan initialDelay, double backoffFactor = 2, TimeSpan? maxDelay = null, IScheduler? scheduler = null)
Parameters
sourceIObservable<T>Source sequence.
maxRetriesintMaximum number of retries.
initialDelayTimeSpanInitial backoff delay.
backoffFactordoubleMultiplier for each retry (default 2).
maxDelayTimeSpan?Optional maximum delay.
schedulerISchedulerScheduler (optional).
Returns
- IObservable<T>
Retried sequence with backoff.
Type Parameters
TElement type.
RetryWithDelay<T>(IObservable<T>, int, Func<int, TimeSpan>)
Retry with exponential.
public static IObservable<T> RetryWithDelay<T>(this IObservable<T> source, int retryCount, Func<int, TimeSpan> delaySelector)
Parameters
sourceIObservable<T>The source.
retryCountintThe retry count.
delaySelectorFunc<int, TimeSpan>The delay selector.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
RetryWithFixedDelay<T>(IObservable<T>, int, TimeSpan)
Retry with fixed backoff.
public static IObservable<T> RetryWithFixedDelay<T>(this IObservable<T> source, int retryCount, TimeSpan delay)
Parameters
sourceIObservable<T>The source.
retryCountintThe retry count.
delayTimeSpanThe delay.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
SampleLatest<T>(IObservable<T>, IObservable<object>)
Sample the latest value whenever a trigger fires.
public static IObservable<T> SampleLatest<T>(this IObservable<T> source, IObservable<object> trigger)
Parameters
sourceIObservable<T>The source.
triggerIObservable<object>The trigger.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
ScanWithInitial<TSource, TAccumulate>(IObservable<TSource>, TAccumulate, Func<TAccumulate, TSource, TAccumulate>)
Scan that always emits the initial value first.
public static IObservable<TAccumulate> ScanWithInitial<TSource, TAccumulate>(this IObservable<TSource> source, TAccumulate initial, Func<TAccumulate, TSource, TAccumulate> accumulator)
Parameters
sourceIObservable<TSource>The source.
initialTAccumulateThe initial.
accumulatorFunc<TAccumulate, TSource, TAccumulate>The accumulator.
Returns
- IObservable<TAccumulate>
An IObservable of TAccumulate.
Type Parameters
TSourceThe type of the source.
TAccumulateThe type of the accumulate.
ScheduleSafe(IScheduler?, Action)
Schedules an action immediately if scheduler null, else on scheduler.
public static IDisposable ScheduleSafe(this IScheduler? scheduler, Action action)
Parameters
schedulerISchedulerScheduler.
actionActionAction.
Returns
- IDisposable
Disposable for the scheduled action.
ScheduleSafe(IScheduler?, TimeSpan, Action)
Schedules an action after a due time.
public static IDisposable ScheduleSafe(this IScheduler? scheduler, TimeSpan dueTime, Action action)
Parameters
Returns
- IDisposable
Disposable for the scheduled action.
Schedule<T>(IObservable<T>, DateTimeOffset, IScheduler)
Schedules the specified due time.
public static IObservable<T> Schedule<T>(this IObservable<T> source, DateTimeOffset dueTime, IScheduler scheduler)
Parameters
sourceIObservable<T>The value.
dueTimeDateTimeOffsetThe due time.
schedulerISchedulerThe scheduler.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
Schedule<T>(IObservable<T>, DateTimeOffset, IScheduler, Action<T>)
Schedules the specified due time.
public static IObservable<T> Schedule<T>(this IObservable<T> source, DateTimeOffset dueTime, IScheduler scheduler, Action<T> action)
Parameters
sourceIObservable<T>The value.
dueTimeDateTimeOffsetThe due time.
schedulerISchedulerThe scheduler.
actionAction<T>The action.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
Schedule<T>(IObservable<T>, IScheduler, Func<T, T>)
Schedules the specified due time.
public static IObservable<T> Schedule<T>(this IObservable<T> source, IScheduler scheduler, Func<T, T> function)
Parameters
sourceIObservable<T>The value.
schedulerISchedulerThe scheduler.
functionFunc<T, T>The function.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
Schedule<T>(IObservable<T>, TimeSpan, IScheduler)
Schedules the specified due time.
public static IObservable<T> Schedule<T>(this IObservable<T> source, TimeSpan dueTime, IScheduler scheduler)
Parameters
sourceIObservable<T>The value.
dueTimeTimeSpanThe due time.
schedulerISchedulerThe scheduler.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
Schedule<T>(IObservable<T>, TimeSpan, IScheduler, Action<T>)
Schedules the specified due time.
public static IObservable<T> Schedule<T>(this IObservable<T> source, TimeSpan dueTime, IScheduler scheduler, Action<T> action)
Parameters
sourceIObservable<T>The value.
dueTimeTimeSpanThe due time.
schedulerISchedulerThe scheduler.
actionAction<T>The action.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
Schedule<T>(IObservable<T>, TimeSpan, IScheduler, Func<T, T>)
Schedules the specified due time.
public static IObservable<T> Schedule<T>(this IObservable<T> source, TimeSpan dueTime, IScheduler scheduler, Func<T, T> function)
Parameters
sourceIObservable<T>The value.
dueTimeTimeSpanThe due time.
schedulerISchedulerThe scheduler.
functionFunc<T, T>The function.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
Schedule<T>(T, DateTimeOffset, IScheduler)
Schedules the specified due time.
public static IObservable<T> Schedule<T>(this T value, DateTimeOffset dueTime, IScheduler scheduler)
Parameters
valueTThe value.
dueTimeDateTimeOffsetThe due time.
schedulerISchedulerThe scheduler.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
Schedule<T>(T, DateTimeOffset, IScheduler, Action<T>)
Schedules the specified due time.
public static IObservable<T> Schedule<T>(this T value, DateTimeOffset dueTime, IScheduler scheduler, Action<T> action)
Parameters
valueTThe value.
dueTimeDateTimeOffsetThe due time.
schedulerISchedulerThe scheduler.
actionAction<T>The action.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
Schedule<T>(T, IScheduler, Func<T, T>)
Schedules the specified due time.
public static IObservable<T> Schedule<T>(this T value, IScheduler scheduler, Func<T, T> function)
Parameters
valueTThe value.
schedulerISchedulerThe scheduler.
functionFunc<T, T>The function.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
Schedule<T>(T, TimeSpan, IScheduler)
Schedules a single value after a delay.
public static IObservable<T> Schedule<T>(this T value, TimeSpan dueTime, IScheduler scheduler)
Parameters
valueTValue.
dueTimeTimeSpanDelay.
schedulerISchedulerScheduler.
Returns
- IObservable<T>
Observable that emits the value.
Type Parameters
TValue type.
Schedule<T>(T, TimeSpan, IScheduler, Action<T>)
Schedules the specified due time.
public static IObservable<T> Schedule<T>(this T value, TimeSpan dueTime, IScheduler scheduler, Action<T> action)
Parameters
valueTThe value.
dueTimeTimeSpanThe due time.
schedulerISchedulerThe scheduler.
actionAction<T>The action.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
Schedule<T>(T, TimeSpan, IScheduler, Func<T, T>)
Schedules the specified due time.
public static IObservable<T> Schedule<T>(this T value, TimeSpan dueTime, IScheduler scheduler, Func<T, T> function)
Parameters
valueTThe value.
dueTimeTimeSpanThe due time.
schedulerISchedulerThe scheduler.
functionFunc<T, T>The function.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
SelectAsyncConcurrent<TSource, TResult>(IObservable<TSource>, Func<TSource, Task<TResult>>, int)
Projects each element to a task with limited concurrency.
public static IObservable<TResult> SelectAsyncConcurrent<TSource, TResult>(this IObservable<TSource> source, Func<TSource, Task<TResult>> selector, int maxConcurrency)
Parameters
sourceIObservable<TSource>Source sequence.
selectorFunc<TSource, Task<TResult>>Task selector.
maxConcurrencyintMax concurrency.
Returns
- IObservable<TResult>
Merged sequence of task results.
Type Parameters
TSourceSource type.
TResultResult type.
SelectAsyncSequential<TSource, TResult>(IObservable<TSource>, Func<TSource, Task<TResult>>)
Projects each element to a task executed sequentially.
public static IObservable<TResult> SelectAsyncSequential<TSource, TResult>(this IObservable<TSource> source, Func<TSource, Task<TResult>> selector)
Parameters
sourceIObservable<TSource>Source sequence.
selectorFunc<TSource, Task<TResult>>Task selector.
Returns
- IObservable<TResult>
Sequence of results preserving order.
Type Parameters
TSourceSource element type.
TResultResult type.
SelectAsync<TSource, TResult>(IObservable<TSource>, Func<TSource, CancellationToken, Task<TResult>>)
Maps values to async operations without losing ordering or cancellation semantics.
public static IObservable<TResult> SelectAsync<TSource, TResult>(this IObservable<TSource> source, Func<TSource, CancellationToken, Task<TResult>> asyncSelector)
Parameters
sourceIObservable<TSource>The source.
asyncSelectorFunc<TSource, CancellationToken, Task<TResult>>The asynchronous selector.
Returns
- IObservable<TResult>
An IObservable of TResult.
Type Parameters
TSourceThe type of the source.
TResultThe type of the result.
SelectAsync<TSource, TResult>(IObservable<TSource>, Func<TSource, Task<TResult>>)
Maps values to async operations without losing ordering or cancellation semantics.
public static IObservable<TResult> SelectAsync<TSource, TResult>(this IObservable<TSource> source, Func<TSource, Task<TResult>> asyncSelector)
Parameters
sourceIObservable<TSource>The source.
asyncSelectorFunc<TSource, Task<TResult>>The asynchronous selector.
Returns
- IObservable<TResult>
An IObservable of TResult.
Type Parameters
TSourceThe type of the source.
TResultThe type of the result.
SelectLatestAsync<TSource, TResult>(IObservable<TSource>, Func<TSource, Task<TResult>>)
Projects each element to a task but only latest result is emitted.
public static IObservable<TResult> SelectLatestAsync<TSource, TResult>(this IObservable<TSource> source, Func<TSource, Task<TResult>> selector)
Parameters
sourceIObservable<TSource>Source sequence.
selectorFunc<TSource, Task<TResult>>Task selector.
Returns
- IObservable<TResult>
Sequence of latest task results.
Type Parameters
TSourceSource type.
TResultResult type.
Shuffle<T>(IObservable<T[]>)
Randomly shuffles arrays emitted by the source.
public static IObservable<T[]> Shuffle<T>(this IObservable<T[]> source)
Parameters
sourceIObservable<T[]>Source array sequence.
Returns
- IObservable<T[]>
Sequence of shuffled arrays (in-place).
Type Parameters
TArray element type.
SkipWhileNull<T>(IObservable<T>)
Skip null values until the first non-null appears.
public static IObservable<T> SkipWhileNull<T>(this IObservable<T> source) where T : class
Parameters
sourceIObservable<T>The source.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
Start(Action, IScheduler?)
Invokes the action asynchronously surfacing the result through a Unit observable.
public static IObservable<Unit> Start(Action action, IScheduler? scheduler)
Parameters
actionActionAction to run.
schedulerISchedulerScheduler (optional).
Returns
- IObservable<Unit>
A sequence producing Unit upon completion.
Start<TResult>(Func<TResult>, IScheduler?)
Invokes the specified function asynchronously surfacing the result.
public static IObservable<TResult> Start<TResult>(Func<TResult> function, IScheduler? scheduler)
Parameters
functionFunc<TResult>Function to run.
schedulerISchedulerScheduler.
Returns
- IObservable<TResult>
A sequence producing the function result.
Type Parameters
TResultResult type.
SubscribeAsync<T>(IObservable<T>, Func<T, Task>)
Subscribes allowing asynchronous operations to be executed without blocking the source.
public static IDisposable SubscribeAsync<T>(this IObservable<T> source, Func<T, Task> onNext)
Parameters
sourceIObservable<T>Observable sequence to subscribe to.
onNextFunc<T, Task>Action to invoke for each element in the observable sequence.
Returns
- IDisposable
IDisposable object used to unsubscribe from the observable sequence.
Type Parameters
TThe type of the elements in the source sequence.
SubscribeAsync<T>(IObservable<T>, Func<T, Task>, Action)
Subscribes allowing asynchronous operations to be executed without blocking the source.
public static IDisposable SubscribeAsync<T>(this IObservable<T> source, Func<T, Task> onNext, Action onCompleted)
Parameters
sourceIObservable<T>Observable sequence to subscribe to.
onNextFunc<T, Task>Action to invoke for each element in the observable sequence.
onCompletedActionThe on completed.
Returns
- IDisposable
IDisposable object used to unsubscribe from the observable sequence.
Type Parameters
TThe type of the elements in the source sequence.
SubscribeAsync<T>(IObservable<T>, Func<T, Task>, Action<Exception>)
Subscribes allowing asynchronous operations to be executed without blocking the source.
public static IDisposable SubscribeAsync<T>(this IObservable<T> source, Func<T, Task> onNext, Action<Exception> onError)
Parameters
sourceIObservable<T>Observable sequence to subscribe to.
onNextFunc<T, Task>Action to invoke for each element in the observable sequence.
onErrorAction<Exception>The on error.
Returns
- IDisposable
IDisposable object used to unsubscribe from the observable sequence.
Type Parameters
TThe type of the elements in the source sequence.
SubscribeAsync<T>(IObservable<T>, Func<T, Task>, Action<Exception>, Action)
Subscribes allowing asynchronous operations to be executed without blocking the source.
public static IDisposable SubscribeAsync<T>(this IObservable<T> source, Func<T, Task> onNext, Action<Exception> onError, Action onCompleted)
Parameters
sourceIObservable<T>Observable sequence to subscribe to.
onNextFunc<T, Task>Action to invoke for each element in the observable sequence.
onErrorAction<Exception>The on error.
onCompletedActionThe on completed.
Returns
- IDisposable
IDisposable object used to unsubscribe from the observable sequence.
Type Parameters
TThe type of the elements in the source sequence.
SubscribeSynchronous<T>(IObservable<T>, Func<T, Task>)
Subscribes an element handler to an observable sequence synchronously.
public static IDisposable SubscribeSynchronous<T>(this IObservable<T> source, Func<T, Task> onNext)
Parameters
sourceIObservable<T>Observable sequence to subscribe to.
onNextFunc<T, Task>Action to invoke for each element in the observable sequence.
Returns
- IDisposable
IDisposable object used to unsubscribe from the observable sequence.
Type Parameters
TThe type of the elements in the source sequence.
SubscribeSynchronous<T>(IObservable<T>, Func<T, Task>, Action)
Subscribes an element handler and a completion handler to an observable sequence synchronously.
public static IDisposable SubscribeSynchronous<T>(this IObservable<T> source, Func<T, Task> onNext, Action onCompleted)
Parameters
sourceIObservable<T>Observable sequence to subscribe to.
onNextFunc<T, Task>Action to invoke for each element in the observable sequence.
onCompletedActionAction to invoke upon graceful termination of the observable sequence.
Returns
- IDisposable
IDisposable object used to unsubscribe from the observable sequence.
Type Parameters
TThe type of the elements in the source sequence.
Exceptions
- ArgumentNullException
sourceoronNextoronCompletedisnull.
SubscribeSynchronous<T>(IObservable<T>, Func<T, Task>, Action<Exception>)
Subscribes an element handler and an exception handler to an observable sequence synchronously.
public static IDisposable SubscribeSynchronous<T>(this IObservable<T> source, Func<T, Task> onNext, Action<Exception> onError)
Parameters
sourceIObservable<T>Observable sequence to subscribe to.
onNextFunc<T, Task>Action to invoke for each element in the observable sequence.
onErrorAction<Exception>Action to invoke upon exceptional termination of the observable sequence.
Returns
- IDisposable
IDisposable object used to unsubscribe from the observable sequence.
Type Parameters
TThe type of the elements in the source sequence.
SubscribeSynchronous<T>(IObservable<T>, Func<T, Task>, Action<Exception>, Action)
Subscribes to the specified source synchronously.
public static IDisposable SubscribeSynchronous<T>(this IObservable<T> source, Func<T, Task> onNext, Action<Exception> onError, Action onCompleted)
Parameters
sourceIObservable<T>The source.
onNextFunc<T, Task>The on next.
onErrorAction<Exception>The on error.
onCompletedActionThe on completed.
Returns
- IDisposable
IDisposable object used to unsubscribe from the observable sequence.
Type Parameters
TThe type of the elements in the source sequence.
SwitchIfEmpty<T>(IObservable<T>, IObservable<T>)
Provide a fallback observable if the source completes without emitting.
public static IObservable<T> SwitchIfEmpty<T>(this IObservable<T> source, IObservable<T> fallback)
Parameters
sourceIObservable<T>The source.
fallbackIObservable<T>The fallback.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
SyncTimer(TimeSpan)
Synchronized timer all instances of this with the same TimeSpan use the same timer.
public static IObservable<DateTime> SyncTimer(TimeSpan timeSpan)
Parameters
timeSpanTimeSpanThe time span.
Returns
- IObservable<DateTime>
An observable sequence producing the shared DateTime ticks.
SyncTimer(TimeSpan, IScheduler)
Synchronized timer all instances of this with the same TimeSpan and scheduler use the same timer.
public static IObservable<DateTime> SyncTimer(TimeSpan timeSpan, IScheduler scheduler)
Parameters
timeSpanTimeSpanThe time span.
schedulerISchedulerScheduler used to emit ticks.
Returns
- IObservable<DateTime>
An observable sequence producing the shared DateTime ticks.
SynchronizeAsync<T>(IObservable<T>)
Synchronizes the asynchronous operations in downstream operations. Use SubscribeSynchronus instead for a simpler version. Call Sync.Dispose() to release the lock in the downstream methods.
public static IObservable<(T Value, IDisposable Sync)> SynchronizeAsync<T>(this IObservable<T> source)
Parameters
sourceIObservable<T>The source.
Returns
- IObservable<(T Value, IDisposable Sync)>
An Observable of T and a release mechanism.
Type Parameters
TThe type of the elements in the source sequence.
SynchronizeSynchronous<T>(IObservable<T>)
Wraps values with a synchronization disposable that completes when disposed.
public static IObservable<(T Value, IDisposable Sync)> SynchronizeSynchronous<T>(this IObservable<T> source)
Parameters
sourceIObservable<T>Source sequence.
Returns
- IObservable<(T Value, IDisposable Sync)>
Sequence of (value, sync handle).
Type Parameters
TElement type.
TakeUntil<TSource>(IObservable<TSource>, Func<TSource, bool>)
Takes elements until predicate returns true for an element (inclusive) then completes.
public static IObservable<TSource> TakeUntil<TSource>(this IObservable<TSource> source, Func<TSource, bool> predicate)
Parameters
sourceIObservable<TSource>Source sequence.
predicateFunc<TSource, bool>Predicate for completion.
Returns
- IObservable<TSource>
Sequence that completes when predicate satisfied.
Type Parameters
TSourceElement type.
ThrottleDistinct<T>(IObservable<T>, TimeSpan)
Throttle but only emit when the value actually changes.
public static IObservable<T> ThrottleDistinct<T>(this IObservable<T> source, TimeSpan throttle)
Parameters
sourceIObservable<T>The source.
throttleTimeSpanThe throttle.
Returns
- IObservable<T>
A throttled distinct sequence.
Type Parameters
TElement type.
ThrottleDistinct<T>(IObservable<T>, TimeSpan, IScheduler)
Throttle but only emit when the value actually changes.
public static IObservable<T> ThrottleDistinct<T>(this IObservable<T> source, TimeSpan throttle, IScheduler scheduler)
Parameters
sourceIObservable<T>The source.
throttleTimeSpanThe throttle.
schedulerISchedulerThe scheduler.
Returns
- IObservable<T>
A throttled distinct sequence.
Type Parameters
TElement type.
ThrottleFirst<T>(IObservable<T>, TimeSpan, IScheduler?)
Emits only the first value in each time window.
public static IObservable<T> ThrottleFirst<T>(this IObservable<T> source, TimeSpan window, IScheduler? scheduler = null)
Parameters
sourceIObservable<T>Source sequence.
windowTimeSpanTime window.
schedulerISchedulerScheduler (optional).
Returns
- IObservable<T>
Throttle-first sequence.
Type Parameters
TElement type.
ThrottleOnScheduler<T>(IObservable<T>, TimeSpan, IScheduler)
Throttles the on scheduler.
public static IObservable<T> ThrottleOnScheduler<T>(this IObservable<T> source, TimeSpan timeSpan, IScheduler scheduler)
Parameters
sourceIObservable<T>The source.
timeSpanTimeSpanThe time span.
schedulerISchedulerThe scheduler.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
ThrottleUntilTrue<T>(IObservable<T>, TimeSpan, Func<T, bool>)
Throttle until a predicate becomes true.
public static IObservable<T> ThrottleUntilTrue<T>(this IObservable<T> source, TimeSpan throttle, Func<T, bool> predicate)
Parameters
sourceIObservable<T>The source.
throttleTimeSpanThe throttle.
predicateFunc<T, bool>The predicate.
Returns
- IObservable<T>
An IObservable of T.
Type Parameters
TThe type.
ToHotTask<T>(IObservable<T>)
Convert an observable to a Task that starts immediately.
public static Task<T> ToHotTask<T>(this IObservable<T> source)
Parameters
sourceIObservable<T>The source.
Returns
- Task<T>
A Task of T.
Type Parameters
TThe type.
ToPropertyObservable<T, TProperty>(T, Expression<Func<T, TProperty>>)
Convert a property getter into an observable that emits on change.
public static IObservable<TProperty> ToPropertyObservable<T, TProperty>(this T source, Expression<Func<T, TProperty>> propertyExpression) where T : INotifyPropertyChanged
Parameters
sourceTThe source.
propertyExpressionExpression<Func<T, TProperty>>The property expression.
Returns
- IObservable<TProperty>
An IObservable of TProperty.
Type Parameters
TThe type of the source.
TPropertyThe type of the property.
Exceptions
- ArgumentException
Expression must be a property.
ToReadOnlyBehavior<T>(T)
A safe wrapper around BehaviorSubject that exposes only the observable.
public static (IObservable<T> Observable, IObserver<T> Observer) ToReadOnlyBehavior<T>(T initialValue)
Parameters
initialValueTThe initial value.
Returns
- (IObservable<T> Observable, IObserver<T> Observer)
A tuple of IObservable and IObserver.
Type Parameters
TThe type.
Using<T>(T, Action<T>, IScheduler?)
Using helper with Action.
public static IObservable<Unit> Using<T>(this T obj, Action<T> action, IScheduler? scheduler = null) where T : IDisposable
Parameters
objTObject to use.
actionAction<T>Action to run.
schedulerISchedulerScheduler.
Returns
- IObservable<Unit>
Completion signal.
Type Parameters
TDisposable type.
Using<T, TResult>(T, Func<T, TResult>, IScheduler?)
Using helper with Func.
public static IObservable<TResult> Using<T, TResult>(this T obj, Func<T, TResult> function, IScheduler? scheduler = null) where T : IDisposable
Parameters
objTObject to use.
functionFunc<T, TResult>Function to invoke.
schedulerISchedulerScheduler.
Returns
- IObservable<TResult>
Observable of result.
Type Parameters
TDisposable type.
TResultResult type.
WaitUntil<T>(IObservable<T>, Func<T, bool>)
Emits the first element matching predicate then completes.
public static IObservable<T> WaitUntil<T>(this IObservable<T> source, Func<T, bool> predicate)
Parameters
sourceIObservable<T>Source sequence.
predicateFunc<T, bool>Predicate.
Returns
- IObservable<T>
Sequence with first matching element.
Type Parameters
TElement type.
WhereFalse(IObservable<bool>)
Filters to false values only.
public static IObservable<bool> WhereFalse(this IObservable<bool> source)
Parameters
sourceIObservable<bool>Boolean source.
Returns
- IObservable<bool>
Sequence of false values.
WhereIsNotNull<T>(IObservable<T>)
Returns only values that are not null. Converts the nullability.
public static IObservable<T> WhereIsNotNull<T>(this IObservable<T> observable)
Parameters
observableIObservable<T>The observable that can contain nulls.
Returns
- IObservable<T>
A non nullable version of the observable that only emits valid values.
Type Parameters
TThe type of value emitted by the observable.
WhereTrue(IObservable<bool>)
Filters to true values only.
public static IObservable<bool> WhereTrue(this IObservable<bool> source)
Parameters
sourceIObservable<bool>Boolean source.
Returns
- IObservable<bool>
Sequence of true values.
While(Func<bool>, Action, IScheduler?)
While construct.
public static IObservable<Unit> While(Func<bool> condition, Action action, IScheduler? scheduler = null)
Parameters
conditionFunc<bool>Condition to evaluate.
actionActionAction to execute.
schedulerISchedulerScheduler.
Returns
- IObservable<Unit>
Observable representing the loop.
WithLimitedConcurrency<T>(IEnumerable<Task<T>>, int)
Executes with limited concurrency.
public static IObservable<T> WithLimitedConcurrency<T>(this IEnumerable<Task<T>> taskFunctions, int maxConcurrency)
Parameters
taskFunctionsIEnumerable<Task<T>>Tasks to execute.
maxConcurrencyintMaximum concurrency.
Returns
- IObservable<T>
A sequence of task results.
Type Parameters
TThe result type.