Skip to content
richardszalay edited this page Sep 14, 2010 · 10 revisions

Merges two sequences through a mapping function, using the latest value from either source

function select(outType : Class, other : IObservable, selector : Function) : IObservable

Where outType is the output type of selector

Where selector is function (x : sourceType, y : otherType) : outType

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.<outType>

Examples

Observable.interval(500).take(2)
    .combineLatest(int, Observable.interval(100), function(x:int, y:int) : int
    {
        return (x+1)*100 + y;
    })
    .subscribeFunc(
        function(value : int) : void { trace(value); },
        function():void { trace("Completed"); }
    );

    // Trace output is:
    // 104
    // 105
    // 106
    // 107
    // 108
    // 109
    // 210
    // Completed