UNPKG

1.16 kBTypeScriptView Raw
1import { Stream } from '../index';
2/**
3 * Puts one stream after the other. *concat* is a factory that takes multiple
4 * streams as arguments, and starts the `n+1`-th stream only when the `n`-th
5 * stream has completed. It concatenates those streams together.
6 *
7 * Marble diagram:
8 *
9 * ```text
10 * --1--2---3---4-|
11 * ...............--a-b-c--d-|
12 * concat
13 * --1--2---3---4---a-b-c--d-|
14 * ```
15 *
16 * Example:
17 *
18 * ```js
19 * import concat from 'xstream/extra/concat'
20 *
21 * const streamA = xs.of('a', 'b', 'c')
22 * const streamB = xs.of(10, 20, 30)
23 * const streamC = xs.of('X', 'Y', 'Z')
24 *
25 * const outputStream = concat(streamA, streamB, streamC)
26 *
27 * outputStream.addListener({
28 * next: (x) => console.log(x),
29 * error: (err) => console.error(err),
30 * complete: () => console.log('concat completed'),
31 * })
32 * ```
33 *
34 * @factory true
35 * @param {Stream} stream1 A stream to concatenate together with other streams.
36 * @param {Stream} stream2 A stream to concatenate together with other streams. Two
37 * or more streams may be given as arguments.
38 * @return {Stream}
39 */
40export default function concat<T>(...streams: Array<Stream<T>>): Stream<T>;