Table of Contents

Class SingleOperator

Namespace
RxSharp.Operators
Assembly
RxSharp.dll

Implements the Single operator. Mirrors rxjs's single.

public static class SingleOperator
Inheritance
System.Object
SingleOperator

Methods

Single<T>(Observable<T>)

Asserts that source emits exactly one value, and emits that value once source completes.

public static Observable<T> Single<T>(this Observable<T> source)

Parameters

source Observable<T>

The source observable to assert singularity of.

Returns

Observable<T>

An observable of the single value emitted by source.

Type Parameters

T

The element type of the source observable.

Remarks

If source completes without ever emitting a value, the result errors with an EmptyErrorException. If source emits more than one value, the result errors with a SequenceErrorException as soon as the second value arrives.

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

Asserts that exactly one value emitted by source satisfies predicate, and emits that value once source completes.

public static Observable<T> Single<T>(this Observable<T> source, Func<T, bool> predicate)

Parameters

source Observable<T>

The source observable to search.

predicate Func<T, bool>

A function that tests each value.

Returns

Observable<T>

An observable of the single matching value.

Type Parameters

T

The element type of the source observable.

Remarks

If source completes without emitting any value at all, the result errors with an EmptyErrorException. If source emits one or more values but none of them satisfy predicate, the result errors with a NotFoundErrorException. If more than one value satisfies predicate, the result errors with a SequenceErrorException as soon as the second match arrives. If predicate throws, that exception is forwarded via OnError instead.

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

Asserts that exactly one value emitted by source satisfies predicate (called with the value and its zero-based emission index), and emits that value once source completes.

public static Observable<T> Single<T>(this Observable<T> source, Func<T, int, bool> predicate)

Parameters

source Observable<T>

The source observable to search.

predicate Func<T, int, bool>

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

Returns

Observable<T>

An observable of the single matching value.

Type Parameters

T

The element type of the source observable.

Remarks

If source completes without emitting any value at all, the result errors with an EmptyErrorException. If source emits one or more values but none of them satisfy predicate, the result errors with a NotFoundErrorException. If more than one value satisfies predicate, the result errors with a SequenceErrorException as soon as the second match arrives. If predicate throws, that exception is forwarded via OnError instead.