Table of Contents

Class TakeWhileOperator

Namespace
RxSharp.Operators
Assembly
RxSharp.dll

Implements the TakeWhile operator. Mirrors rxjs's takeWhile.

public static class TakeWhileOperator
Inheritance
System.Object
TakeWhileOperator

Methods

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

Emits values from source for as long as predicate returns true, then completes as soon as it returns false without waiting for source itself to complete.

public static Observable<T> TakeWhile<T>(this Observable<T> source, Func<T, bool> predicate, bool inclusive = false)

Parameters

source Observable<T>

The source observable to take values from.

predicate Func<T, bool>

A function that tests each value.

inclusive bool

If true, the value that made predicate return false is emitted before completing.

Returns

Observable<T>

An observable of the values from source up to (and, if inclusive, including) the first one that fails predicate.

Type Parameters

T

The element type of the source observable.

Remarks

Equivalent to the indexed overload with the index ignored. If predicate throws, the exception is forwarded via OnError.

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

Emits values from source for as long as predicate, called with the value and its zero-based emission index, returns true, then completes as soon as it returns false without waiting for source itself to complete.

public static Observable<T> TakeWhile<T>(this Observable<T> source, Func<T, int, bool> predicate, bool inclusive = false)

Parameters

source Observable<T>

The source observable to take values from.

predicate Func<T, int, bool>

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

inclusive bool

If true, the value that made predicate return false is emitted before completing.

Returns

Observable<T>

An observable of the values from source up to (and, if inclusive, including) the first one that fails predicate.

Type Parameters

T

The element type of the source observable.

Remarks

If predicate throws, the exception is forwarded via OnError.