-
Notifications
You must be signed in to change notification settings - Fork 8
average
richardszalay edited this page Sep 14, 2010
·
9 revisions
Returns the average value of all the elements in the source sequence
static function average(): IObservable
The returned sequence completes when the source sequence completes.
The returned sequence raises an error if the source sequence raises an error or if the source sequence is empty.
xs = source ys = output
xs ───o───o───o───o─/ 2 4 6 8 │ │ ys ─────────────────o/ 5
xs ───────────────/ │ │ ys ───────────────x
@IObservable.
Observable.range(1, 5)
.average()
.subscribeFunc(
function(value : int) : void { trace(value); },
function():void { trace("Completed"); }
);
// Trace output is:
// 3
// Completed
Observable.empty(int)
.sum()
.subscribeFunc(
function(value : int) : void { trace(value); },
function():void { trace("Completed"); },
function(e:Error) : void { trace(e.message); }
);
// Trace output is:
// Sequence contained no elements