Class WithLatestFromOperator
Extension methods implementing the withLatestFrom operator.
public static class WithLatestFromOperator
- Inheritance
-
System.ObjectWithLatestFromOperator
Methods
WithLatestFrom<T>(Observable<T>, params Observable<T>[])
Combines each value emitted by source with the latest value from every observable in
others, as a list (source value first, then each other's latest value in order), only
when source itself emits. Same-type-only for now (unlike rxjs's heterogeneously-typed
tuple overloads), mirroring how Zip<T>(params Observable<T>[])/CombineLatest<T>(params Observable<T>[])
handle multiple same-type sources.
public static Observable<IReadOnlyList<T>> WithLatestFrom<T>(this Observable<T> source, params Observable<T>[] others)
Parameters
sourceObservable<T>The primary source sequence, driving each output emission.
othersObservable<T>[]The observables whose latest values are combined with each
sourceemission, in order.
Returns
- Observable<IReadOnlyList<T>>
An observable of lists —
[sourceValue, others[0]'s latest, others[1]'s latest, ...]— one persourceemission once every observable inothershas emitted at least once.
Type Parameters
TThe element type shared by
sourceand every observable inothers.
Remarks
No output is produced until every observable in others has emitted at least once. Each
is subscribed to before source, so synchronous ones already have a latest value by the
time source's first (possibly also synchronous) emission arrives. Any of them completing
has no effect on the output — its last known value keeps being used. If any observable errors, the error is
forwarded via OnError. The output completes when source completes, regardless of
others.
WithLatestFrom<TSource, TOther>(Observable<TSource>, Observable<TOther>)
Combines each value emitted by source with the latest value from other
as a tuple, only when source itself emits.
public static Observable<(TSource Source, TOther Other)> WithLatestFrom<TSource, TOther>(this Observable<TSource> source, Observable<TOther> other)
Parameters
sourceObservable<TSource>The primary source sequence, driving each output emission.
otherObservable<TOther>The observable whose latest value is combined with each
sourceemission.
Returns
- Observable<(TSource Source, TOther Other)>
An observable of
(Source, Other)tuples, one persourceemission onceotherhas emitted at least once.
Type Parameters
TSourceThe type of values emitted by
source.TOtherThe type of values emitted by
other.
Remarks
Equivalent to the overload taking a resultSelector, using tuple construction as the selector. See its remarks for full behavior.
WithLatestFrom<TSource, TOther, TResult>(Observable<TSource>, Observable<TOther>, Func<TSource, TOther, TResult>)
Combines each value emitted by source with the latest value from other
via resultSelector, only when source itself emits — other
emitting on its own never produces an output value.
public static Observable<TResult> WithLatestFrom<TSource, TOther, TResult>(this Observable<TSource> source, Observable<TOther> other, Func<TSource, TOther, TResult> resultSelector)
Parameters
sourceObservable<TSource>The primary source sequence, driving each output emission.
otherObservable<TOther>The observable whose latest value is combined with each
sourceemission.resultSelectorFunc<TSource, TOther, TResult>A function combining a
sourcevalue with the latestothervalue.
Returns
- Observable<TResult>
An observable of the combined values, one per
sourceemission onceotherhas emitted at least once.
Type Parameters
TSourceThe type of values emitted by
source.TOtherThe type of values emitted by
other.TResultThe type of values produced by
resultSelector.
Remarks
No output is produced until other has emitted at least once. other
is subscribed to before source, so a synchronous other already has
a latest value by the time source's first (possibly also synchronous) emission arrives.
other completing has no effect on the output — its last known value keeps being used.
If resultSelector throws, or either observable errors, the error is forwarded via
OnError. The output completes when source completes, regardless of other.