Table of Contents

Class PartitionOperator

Namespace
RxSharp.Operators
Assembly
RxSharp.dll

Implements the Partition operator. Mirrors rxjs's partition.

public static class PartitionOperator
Inheritance
System.Object
PartitionOperator

Methods

Partition<T>(Observable<T>, Func<T, bool>)

Splits source into two observables based on predicate: one with the values for which it returns true, the other with the values for which it returns false.

public static (Observable<T> Matched, Observable<T> Unmatched) Partition<T>(this Observable<T> source, Func<T, bool> predicate)

Parameters

source Observable<T>

The source observable to split.

predicate Func<T, bool>

A function that tests each value.

Returns

(Observable<T> Matched, Observable<T> Unmatched)

A tuple of two observables: Matched for values satisfying predicate, Unmatched for the rest.

Type Parameters

T

The element type of the source observable.

Remarks

Matches rxjs's actual implementation (partition.ts, verified against the 7.8.2 tag), which is literally [filter(predicate)(source), filter(not(predicate))(source)]: source is subscribed to independently once per returned observable (twice overall, not shared), so each side has its own fully independent subscription lifetime, error path, and (for the indexed overload) index counter. If predicate throws, both sides receive the exception via OnError, since each invokes it independently for the same value.

Partition<T>(Observable<T>, Func<T, int, bool>)

Splits source into two observables based on predicate, called with each value and its zero-based emission index (tracked independently for each returned observable): one with the values for which it returns true, the other with the values for which it returns false.

public static (Observable<T> Matched, Observable<T> Unmatched) Partition<T>(this Observable<T> source, Func<T, int, bool> predicate)

Parameters

source Observable<T>

The source observable to split.

predicate Func<T, int, bool>

A function that tests each value together with its index since subscription.

Returns

(Observable<T> Matched, Observable<T> Unmatched)

A tuple of two observables: Matched for values satisfying predicate, Unmatched for the rest.

Type Parameters

T

The element type of the source observable.

Remarks

Matches rxjs's actual implementation (partition.ts, verified against the 7.8.2 tag), which is literally [filter(predicate)(source), filter(not(predicate))(source)]: source is subscribed to independently once per returned observable (twice overall, not shared), so each side has its own fully independent subscription lifetime, error path, and index counter. Since both sides observe the same source values in the same order, their index counters stay in lockstep, so the index seen by predicate is the same for a given value regardless of which side is evaluating it. If predicate throws, both sides receive the exception via OnError, since each invokes it independently for the same value.