-
Notifications
You must be signed in to change notification settings - Fork 8
richardszalay edited this page May 20, 2011
·
9 revisions
Merges two sequences through a mapping function while only ever using each value once
function zip(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──────│──────o────/
│ │ │
f(x,y) f(x,y) │
zs ─────o─────────────o───────────/
xs ──o────────x
└──┐ │
│ │
ys ─────o──o──│
│ │
f(x,y) │
zs ─────o──o──x
IObservable.<TResult>
Observable.interval(500).take(5)
.zip(Observable.interval(100).take(2), 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:
// 100 (@ 00:00:00.500)
// 201 (@ 00:00:01.000)
// Completed