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

Emits sequences that contain values buffered into groups of a particular size. To emit arrays after the count elapsed, see [bufferWithCount]

function windowWithCount(count : uint, skip : uint = 0) : IObservable

Remarks

Values are emitted as arrays in groups of count. If the sequence finishes before the buffer is filled, the current buffer will be emited.

If skip is specified, only the first skip items in the buffer will be discarded after being emitted. By default, the entire buffer is discarded after count values.

The returned sequence completes when the source sequence completes

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

Marble Diagrams

xs = source
ys = output
c = count

    0  1  c  3  4
xs ─o──o──o──o──o──/
    │  │  │  │  │  │
    │  │  │  │  │  │
    │  │  │  │  │  │
ys o───────o────────/
   ││  │  ││ │  │  │
y1 └o──o──o/ │  │  │
    0  1  c│ │  │  │
           │ │  │  │
y2         └─o──o──/
             3  4

Return Value

IObservable.< IObservable.<T> >

Examples

Observable.range(0, 10)
    .bufferWithCount(5)
    .subscribe(
        function(values : IObservable) : void
        {
            values
                .take(1)
                .subscribe(function(value:int):void
                 {
                     trace(value);
                 });
        });

    // Trace output is:
    // 0
    // 5