buffer method
inherited
Creates an Observable where each item is a List
containing the items
from the source sequence, batched by the sampler
.
Example with onCount
Observable.range(1, 4)
.buffer(onCount(2))
.listen(print); // prints [1, 2], [3, 4]
Example with onFuture
new Observable.periodic(const Duration(milliseconds: 100), (int i) => i)
.buffer(onFuture(() => new Future.delayed(const Duration(milliseconds: 220))))
.listen(print); // prints [0, 1] [2, 3] [4, 5] ...
Example with onTest
new Observable.periodic(const Duration(milliseconds: 100), (int i) => i)
.buffer(onTest((i) => i % 2 == 0))
.listen(print); // prints [0], [1, 2] [3, 4] [5, 6] ...
Example with onTime
new Observable.periodic(const Duration(milliseconds: 100), (int i) => i)
.buffer(onTime(const Duration(milliseconds: 220)))
.listen(print); // prints [0, 1] [2, 3] [4, 5] ...
Example with onStream
new Observable.periodic(const Duration(milliseconds: 100), (int i) => i)
.buffer(onStream(new Stream.periodic(const Duration(milliseconds: 220), (int i) => i)))
.listen(print); // prints [0, 1] [2, 3] [4, 5] ...
You can create your own sampler by extending StreamView
should the above samplers be insufficient for your use case.
Implementation
Observable<List<T>> buffer(SamplerBuilder<T, List<T>> sampler) =>
transform(new BufferStreamTransformer<T>((Stream<T> stream,
OnDataTransform<T, List<T>> bufferHandler,
OnDataTransform<List<T>, List<T>> scheduleHandler) =>
sampler(stream, bufferHandler, scheduleHandler)));