Table of Contents

Class First

Namespace
Bonsai.Reactive
Assembly
Bonsai.Core.dll

Represents an operator that returns the first element of an observable sequence.

Marble diagram

If the sequence has no elements, First will terminate with an error.

Tip

If you are interested in finding the first element that meets some criteria, consider using the Condition operator before First.

Warning

There are subtle but important differences between using the First operator and Take(1):

  • When the source sequence has no elements, Take(1) will complete successfully, while First will throw an error.
  • When the source sequence emits the first element, Take(1) will immediately cancel the subscription to the source sequence before emitting the notification. First, on the other hand, will emit the notification and only afterwards cancel the subscription to the source sequence.
public class First : Combinator
Inheritance
First
Inherited Members

Methods

Process<TSource>(IObservable<TSource>)

Returns the first element of an observable sequence.

public override IObservable<TSource> Process<TSource>(IObservable<TSource> source)

Parameters

source IObservable<TSource>

The sequence to take the first element from.

Returns

IObservable<TSource>

An observable sequence containing the first element of the source sequence.

Type Parameters

TSource

The type of the elements in the source sequence.