Skip to content
richardszalay edited this page May 20, 2011 · 8 revisions

Emits the last value from a source sequence or the default value if the source sequence is empty.

function lastOrDefault() : IObservable.<T>

Remarks

If the source sequence is empty, the default value for the sequence type will be emitted. The value will be 0 for numbers, false for Boolean, and null for all other values.

The returned sequence completes when the source sequence completes.

The returned sequence errors when the source sequences errors

Marble Diagrams

xs = source
ys = output

xs  ──o───o─o────o──/
                 │
                 └──┐
                    │
ys  ────────────────o/


xs  ────────────────/
                    │
                    │
                    │
ys  ────────────────o
               0/false/null

Return Value

IObservable.<T>

Examples

var source : IObservable = Observable.empty()
    .lastOrDefault();

source.subscribe(
    function(value : int) : void { trace(value; },
    function() : void { trace("Completed!"); }
    );

// Trace output is:
// 0
// Completed!
Clone this wiki locally