-
Notifications
You must be signed in to change notification settings - Fork 8
bufferWithCount
richardszalay edited this page May 20, 2011
·
10 revisions
Emits the values from a source sequence in groups of a specific size
function bufferWithCount(count : uint, skip : uint = 0) : IObservable.<Array>
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.
xs = source
ys = output
c = count
0 1 c 3 4
xs ─o──o──o──o──o──/
│ └──┤ │ └──┤
└─────┤ └─────┤
│ │
ys ───────o────────o
[0,1,c] [3,4]
IObservable.<Array>
Observable.range(0, 10)
.bufferWithCount(5)
.subscribe(
function(values : Array) : void
{
trace(values.join(", "));
});
// Trace output is:
// 0, 1, 2, 3, 4
// 5, 6, 7, 8, 9
Observable.range(0, 10)
.bufferWithCount(5, 3)
.subscribe(
function(values : Array) : void
{
trace(values.join(", "));
});
// Trace output is:
// 0, 1, 2, 3, 4
// 3, 4, 5, 6, 7
// 6, 7, 8, 9