-
Notifications
You must be signed in to change notification settings - Fork 8
combineLatest
richardszalay edited this page May 20, 2011
·
10 revisions
Merges two sequences through a mapping function, using the latest value from either source
function combineLatest(other : IObservable.<TOther>,
selector : Function) : IObservable.<TResult>
Where selector is function (x : T, y : TOther) : TResult
The returned sequence completes when the source sequence completes.
The returned sequence raises an error if the source sequence raises an error or if selector throws an error.
xs = source
ys = other
zs = output
f = selector
xs ──o────────────────o────────────
└──┬──────┐ ____/│\____
│ │/ │ \
ys ─────o──────o──────│──────o────/
│ │ │ │ │
f(x,y) f(x,y) f(x,y) f(x,y) │
zs ─────o──────o──────o──────o────/
xs ──o────────x
└──┬──┐ │
│ │ │
ys ─────o──o──│
│ │ │
f(x,y) │
zs ─────o──o──x
IObservable.<TResult>
Observable.interval(500).take(2)
.combineLatest(Observable.interval(100), function(x:int, y:int) : int
{
return (x+1)*100 + y;
})
.subscribe(
function(value : int) : void { trace(value); },
function():void { trace("Completed"); }
);
// Trace output is:
// 104
// 105
// 106
// 107
// 108
// 109
// 210
// Completed