forked from richardszalay/raix
-
Notifications
You must be signed in to change notification settings - Fork 0
firstOrDefault
richardszalay edited this page Sep 14, 2010
·
8 revisions
Emits the first value from a source sequence or the default value if the source sequence is empty.
function firstOrDefault() : IObservable
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 │ │ │ │ ys ──o/
xs ──────/ │ │ │ │ ys ──────o defaultValue
IObservable.<sourceType>
var source : IObservable = Observable.empty(int)
.firstOrDefault();
source.subscribeFunc(
function(value : int) : void { trace(value; },
function() : void { trace("Completed!"); }
);
// Trace output is:
// 0
// Completed!