Table of Contents

Class LastOrDefault

Namespace
Bonsai.Reactive
Assembly
Bonsai.Core.dll

Represents an operator that returns the last element of an observable sequence, or a default value if no such element exists.

Marble diagram

If the sequence has no elements, LastOrDefault will emit a default value before terminating successfully. This is a subtle but important difference between the LastOrDefault operator and TakeLast(1), which will also complete successfully when the source sequence is empty, but will not emit any values.

Tip

LastOrDefault is one of the simplest and most efficient ways of capturing the end of an observable sequence explicitly as a notification in the workflow. You can use it to react to the termination of a sequence regardless of whether that sequence produces values.

public class LastOrDefault : Combinator
Inheritance
LastOrDefault
Inherited Members

Methods

Process<TSource>(IObservable<TSource>)

Returns the last element of an observable sequence, or a default value if no such element exists.

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

Parameters

source IObservable<TSource>

The sequence to take the last element from.

Returns

IObservable<TSource>

An observable sequence containing the last element of the source sequence, or a default value if no such element exists.

Type Parameters

TSource

The type of the elements in the source sequence.