-
Notifications
You must be signed in to change notification settings - Fork 8
lastOrDefault
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>
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
xs = source
ys = output
xs ──o───o─o────o──/
│
└──┐
│
ys ────────────────o/
xs ────────────────/
│
│
│
ys ────────────────o
0/false/null
IObservable.<T>
var source : IObservable = Observable.empty()
.lastOrDefault();
source.subscribe(
function(value : int) : void { trace(value; },
function() : void { trace("Completed!"); }
);
// Trace output is:
// 0
// Completed!