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

Emits the first value from a source sequence as long it is the only value in the sequence.

function single() : IObservable.<T>

Remarks

The returned sequence completes when the source sequence completes with values.

The returned sequence errors when the source sequences errors, if the source sequence completes without any values, or if the source sequence emits more than one value.

Marble Diagrams

xs = source
ys = output


xs  ──o─────────────/
      │
      └─────────────┐
                    │
ys  ────────────────o/


xs  ────────────────/
                    │
                    │
                    │
ys  ────────────────x


xs  ──o──────────o
                 │
                 │
                 │
ys  ─────────────x

Return Value

IObservable.<T>

Examples

var source : IObservable = Observable.range(0, 5)
    .single();

source.subscribe(
    function(value : int) : void { trace(value; },
    function() : void { trace("Completed!"); },
    function(err : Error) : void { trace("Error: " + err.message); }
    );

// Trace output is:
// Error: The sequence contained more than one value
// 
Clone this wiki locally