Table of Contents

Class GroupByOperator

Namespace
RxSharp.Operators
Assembly
RxSharp.dll

The groupBy operator. See the main overload below for full behavior.

public static class GroupByOperator
Inheritance
System.Object
GroupByOperator

Methods

GroupBy<T, TKey>(Observable<T>, Func<T, TKey>)

Groups source values by keySelector, one IGroupedObservable<TKey, T> per distinct key.

public static Observable<IGroupedObservable<TKey, T>> GroupBy<T, TKey>(this Observable<T> source, Func<T, TKey> keySelector) where TKey : notnull

Parameters

source Observable<T>

The source observable.

keySelector Func<T, TKey>

Selects the grouping key for each value.

Returns

Observable<IGroupedObservable<TKey, T>>

An observable of groups, one per distinct key.

Type Parameters

T

The element type of the source.

TKey

The type of the shared key.

GroupBy<T, TKey, TElement>(Observable<T>, Func<T, TKey>, Func<T, TElement>)

Groups source values by keySelector, projecting each value with elementSelector before it's added to its group.

public static Observable<IGroupedObservable<TKey, TElement>> GroupBy<T, TKey, TElement>(this Observable<T> source, Func<T, TKey> keySelector, Func<T, TElement> elementSelector) where TKey : notnull

Parameters

source Observable<T>

The source observable.

keySelector Func<T, TKey>

Selects the grouping key for each value.

elementSelector Func<T, TElement>

Projects each source value into the value emitted by its group.

Returns

Observable<IGroupedObservable<TKey, TElement>>

An observable of groups, one per distinct key.

Type Parameters

T

The element type of the source.

TKey

The type of the shared key.

TElement

The type of the projected group elements.

GroupBy<T, TKey, TElement, TDuration>(Observable<T>, Func<T, TKey>, Func<T, TElement>, Func<IGroupedObservable<TKey, TElement>, Observable<TDuration>>?)

Groups source values by keySelector into one IGroupedObservable<TKey, T> per distinct key. If durationSelector is given, it is subscribed once per newly created group; the group closes (completes, and a later value with the same key starts a brand-new group) as soon as that duration observable emits or completes. A callback failure in any of keySelector/elementSelector/ durationSelector is treated as fatal for the whole operation (matches rxjs): it errors the outer subscriber AND every currently open group, not just the group that happened to trigger it. Deliberately does not implement rxjs's ref-counted "close the source once the outer and every inner group have been unsubscribed" behavior — disposing the outer subscription always tears down the source directly.

public static Observable<IGroupedObservable<TKey, TElement>> GroupBy<T, TKey, TElement, TDuration>(this Observable<T> source, Func<T, TKey> keySelector, Func<T, TElement> elementSelector, Func<IGroupedObservable<TKey, TElement>, Observable<TDuration>>? durationSelector) where TKey : notnull

Parameters

source Observable<T>

The source observable.

keySelector Func<T, TKey>

Selects the grouping key for each value.

elementSelector Func<T, TElement>

Projects each source value into the value emitted by its group.

durationSelector Func<IGroupedObservable<TKey, TElement>, Observable<TDuration>>?

Given a newly created group, returns an observable whose first emission or completion closes that group.

Returns

Observable<IGroupedObservable<TKey, TElement>>

An observable of groups, one per distinct key (and per duration-selector-bounded lifetime, if given).

Type Parameters

T

The element type of the source.

TKey

The type of the shared key.

TElement

The type of the projected group elements.

TDuration

The (unused) element type of the duration observable.