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

Returns the number of elements in the source sequence

static function count() : IObservable.<int>

Remarks

When the sequence completes, returns the number of values in the sequence.

The returned sequence completes when the source sequence completes.

The returned sequence raises an error if the source sequence raises an error.

Marble Diagrams

xs = source
ys = output

xs ───o───o──o──o─/
                  │
                  │
ys ───────────────o/
                  4

xs ───────────────/
                  │
                  │
ys ───────────────o/
                  0
`

h3. Return Value

@IObservable.<uint>@

h2. Examples

```as3
Observable.range(10, 5)
    .count()
    .subscribe(
        function(value : int) : void { trace(value); },
        function():void { trace("Completed"); }
    );

    // Trace output is:
    // 5
    // Completed
// Counts the number of even numbers between 1 and 50 (inclusive)
Observable.range(1, 50)
    .filter(function(x:int):Boolean { return (x % 2) == 0; })
    .count()
    .subscribe(
        function(value : int) : void { trace(value); },
        function():void { trace("Completed"); }
    );

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