Skip to content
richard.szalay edited this page May 15, 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

Remarks

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.

Marble Diagrams

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

Return Value

IObservable.<TResult>

Examples

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
Clone this wiki locally