windowCount method

Observable<Stream<T>> windowCount (int count, [ int startBufferEvery = 0 ])

Buffers a number of values from the source Observable by count then emits the values inside the buffer as a new Stream, and starts a new buffer each startBufferEvery values. If startBufferEvery is not provided or is null, then new buffers are started immediately at the start of the source and when each buffer closes and is emitted.

Example

count is the maximum size of the buffer emitted

Observable.range(1, 4)
  .windowCount(2)
  .doOnData((_) => print('new Stream emitted))
  .flatMap((stream) => stream)
  .listen(print); // prints new Stream emitted, 1, 2, new Stream emitted, 3, 4 done!

Example

if startBufferEvery is 2, then a new buffer will be started on every other value from the source. A new buffer is started at the beginning of the source by default.

Observable.range(1, 5)
  .windowCount(3, 2)
  .doOnData((_) => print('new Stream emitted))
  .flatMap((stream) => stream)
  .listen(print); // prints new Stream emitted, 1, 2, 3 new Stream emitted 3, 4, 5 new Stream emitted 5 done!

Implementation

Observable<Stream<T>> windowCount(int count, [int startBufferEvery = 0]) =>
    transform(
        new WindowStreamTransformer<T>(onCount(count, startBufferEvery)));