UNPKG

3.99 kBTypeScriptView Raw
1/**
2 * Wrapper around `IterableIterator` interface
3 * offering a set of helpers to deal with iterations in a simple way
4 *
5 * @remarks Since 0.0.7
6 * @public
7 */
8export declare class Stream<T> implements IterableIterator<T> {
9 /**
10 * Create an empty stream of T
11 * @remarks Since 0.0.1
12 */
13 static nil<T>(): Stream<T>;
14 /**
15 * Create a stream of T from a variable number of elements
16 *
17 * @param elements - Elements used to create the Stream
18 * @remarks Since 2.12.0
19 */
20 static of<T>(...elements: T[]): Stream<T>;
21 /**
22 * Create a Stream based on `g`
23 * @param g - Underlying data of the Stream
24 */
25 constructor(/** @internal */ g: IterableIterator<T>);
26 next(): IteratorResult<T>;
27 [Symbol.iterator](): IterableIterator<T>;
28 /**
29 * Map all elements of the Stream using `f`
30 *
31 * WARNING: It closes the current stream
32 *
33 * @param f - Mapper function
34 * @remarks Since 0.0.1
35 */
36 map<U>(f: (v: T) => U): Stream<U>;
37 /**
38 * Flat map all elements of the Stream using `f`
39 *
40 * WARNING: It closes the current stream
41 *
42 * @param f - Mapper function
43 * @remarks Since 0.0.1
44 */
45 flatMap<U>(f: (v: T) => IterableIterator<U>): Stream<U>;
46 /**
47 * Drop elements from the Stream while `f(element) === true`
48 *
49 * WARNING: It closes the current stream
50 *
51 * @param f - Drop condition
52 * @remarks Since 0.0.1
53 */
54 dropWhile(f: (v: T) => boolean): Stream<T>;
55 /**
56 * Drop `n` first elements of the Stream
57 *
58 * WARNING: It closes the current stream
59 *
60 * @param n - Number of elements to drop
61 * @remarks Since 0.0.1
62 */
63 drop(n: number): Stream<T>;
64 /**
65 * Take elements from the Stream while `f(element) === true`
66 *
67 * WARNING: It closes the current stream
68 *
69 * @param f - Take condition
70 * @remarks Since 0.0.1
71 */
72 takeWhile(f: (v: T) => boolean): Stream<T>;
73 /**
74 * Take `n` first elements of the Stream
75 *
76 * WARNING: It closes the current stream
77 *
78 * @param n - Number of elements to take
79 * @remarks Since 0.0.1
80 */
81 take(n: number): Stream<T>;
82 /**
83 * Filter elements of the Stream
84 *
85 * WARNING: It closes the current stream
86 *
87 * @param f - Elements to keep
88 * @remarks Since 1.23.0
89 */
90 filter<U extends T>(f: (v: T) => v is U): Stream<U>;
91 /**
92 * Filter elements of the Stream
93 *
94 * WARNING: It closes the current stream
95 *
96 * @param f - Elements to keep
97 * @remarks Since 0.0.1
98 */
99 filter(f: (v: T) => boolean): Stream<T>;
100 /**
101 * Check whether all elements of the Stream are successful for `f`
102 *
103 * WARNING: It closes the current stream
104 *
105 * @param f - Condition to check
106 * @remarks Since 0.0.1
107 */
108 every(f: (v: T) => boolean): boolean;
109 /**
110 * Check whether one of the elements of the Stream is successful for `f`
111 *
112 * WARNING: It closes the current stream
113 *
114 * @param f - Condition to check
115 * @remarks Since 0.0.1
116 */
117 has(f: (v: T) => boolean): [boolean, T | null];
118 /**
119 * Join `others` Stream to the current Stream
120 *
121 * WARNING: It closes the current stream and the other ones (as soon as it iterates over them)
122 *
123 * @param others - Streams to join to the current Stream
124 * @remarks Since 0.0.1
125 */
126 join(...others: IterableIterator<T>[]): Stream<T>;
127 /**
128 * Take the `nth` element of the Stream of the last (if it does not exist)
129 *
130 * WARNING: It closes the current stream
131 *
132 * @param nth - Position of the element to extract
133 * @remarks Since 0.0.12
134 */
135 getNthOrLast(nth: number): T | null;
136}
137/**
138 * Create a Stream based on `g`
139 *
140 * @param g - Underlying data of the Stream
141 *
142 * @remarks Since 0.0.7
143 * @public
144 */
145export declare function stream<T>(g: IterableIterator<T>): Stream<T>;