Skip to content
richardszalay edited this page May 20, 2011 · 11 revisions

Defers selection of the sequence to be looked up from a dictionary.

function lookup(keySelector : Function, 
    dictionary : Dictionary) : IObservable.<T>

Where keySelector is function () : Object

Remarks

Similar to defer and ifElse, lookup allows the selection of the actual sequence to be defered until the point of subscription. At this point, keySelector will be called and the return value will be used as a key into dictionary. The IObservable found in the dictionary will be subscribed to.

The returned sequence completes when the approprate sequence completes.

The returned sequence errors if the looked up sequence errors or if keySelector throws an error

Marble Diagrams

k() = keySelector
d   = dictionary

xs     ─┐
       k()
       key
d[key]  └───o─────o──/
            │     │  │
zs     ─────o─────o──/

Return Value

IObservable.<T>

Examples

var dictionary : Dictionary = new Dictionary();
dictionary["keyA"] = Observable.value(int, 1);
dictionary["keyB"] = Observable.value(int, 2);
dictionary["keyC"] = Observable.value(int, 3);

Observable.lookup(function():String { return "keyB"; }, dictionary)
    .subscribe(
        function(x:int) : void { trace(x); },
        function() : void { trace("Completed"); }
    );

    // Trace output is:
    // 2
    // Completed
Clone this wiki locally