UNPKG

901 BTypeScriptView Raw
1import { Stream } from '../index';
2/**
3 * Buffers a stream using a separator stream. Returns a stream that emits
4 * arrays.
5 *
6 * Marble diagram:
7 *
8 * ```text
9 * --1--2--3--4--5--6--7--8--9|
10 * buffer( -a---------b---------c| )
11 * ---------[1,2,3]---[4,5,6]---[7,8,9]|
12 * ```
13 *
14 * Example:
15 *
16 * ```js
17 * import buffer from 'xstream/extra/buffer'
18 *
19 * const source = xs.periodic(50).take(10);
20 * const separator = xs.periodic(170).take(3);
21 * const buffered = source.compose(buffer(separator));
22 *
23 * buffered.addListener({
24 * next: arr => console.log(arr),
25 * error: err => console.error(err)
26 * });
27 * ```
28 *
29 * ```text
30 * > [0, 1, 2]
31 * > [3, 4, 5]
32 * > [6, 7, 8]
33 * ```
34 *
35 * @param {Stream} separator Some other stream that is used to know when to
36 * split the output stream.
37 * @return {Stream}
38 */
39export default function buffer<T>(s: Stream<any>): (ins: Stream<T>) => Stream<Array<T>>;