Skip to content
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

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────/
        │      │      │      │    │
      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

Return Value

IObservable.<TResult>

Examples

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