@daiso-tech/core 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/event-bus/contracts/_shared.js +8 -1
- package/dist/cjs/event-bus/contracts/_shared.js.map +1 -1
- package/dist/cjs/event-bus/implementations/_shared/test-utilities/event-bus-adapter.test-suite.js +2 -2
- package/dist/cjs/event-bus/implementations/_shared/test-utilities/event-bus-adapter.test-suite.js.map +1 -1
- package/dist/cjs/event-bus/implementations/event-bus/event-bus-manager.js +14 -7
- package/dist/cjs/event-bus/implementations/event-bus/event-bus-manager.js.map +1 -1
- package/dist/cjs/storage/implementations/_shared/test-utilities/storage-adapter.test-suite.js +2 -2
- package/dist/cjs/storage/implementations/_shared/test-utilities/storage-adapter.test-suite.js.map +1 -1
- package/dist/cjs/storage/implementations/storage/storage-manager.js +17 -7
- package/dist/cjs/storage/implementations/storage/storage-manager.js.map +1 -1
- package/dist/cjs/storage/implementations/storage/with-event-storage-adapter.js +8 -7
- package/dist/cjs/storage/implementations/storage/with-event-storage-adapter.js.map +1 -1
- package/dist/esm/event-bus/contracts/_shared.js +6 -0
- package/dist/esm/event-bus/contracts/_shared.js.map +1 -1
- package/dist/esm/event-bus/implementations/_shared/test-utilities/event-bus-adapter.test-suite.js +1 -1
- package/dist/esm/event-bus/implementations/_shared/test-utilities/event-bus-adapter.test-suite.js.map +1 -1
- package/dist/esm/event-bus/implementations/event-bus/event-bus-manager.js +15 -8
- package/dist/esm/event-bus/implementations/event-bus/event-bus-manager.js.map +1 -1
- package/dist/esm/storage/implementations/_shared/test-utilities/storage-adapter.test-suite.js +1 -1
- package/dist/esm/storage/implementations/_shared/test-utilities/storage-adapter.test-suite.js.map +1 -1
- package/dist/esm/storage/implementations/storage/storage-manager.js +18 -8
- package/dist/esm/storage/implementations/storage/storage-manager.js.map +1 -1
- package/dist/esm/storage/implementations/storage/with-event-storage-adapter.js +8 -7
- package/dist/esm/storage/implementations/storage/with-event-storage-adapter.js.map +1 -1
- package/dist/types/collection/contracts/async-collection.contract.d.ts +227 -35
- package/dist/types/collection/contracts/collection.contract.d.ts +221 -35
- package/dist/types/event-bus/contracts/_shared.d.ts +6 -0
- package/dist/types/event-bus/contracts/event-bus-manager.contract.d.ts +107 -7
- package/dist/types/event-bus/contracts/event-bus.contract.d.ts +50 -22
- package/dist/types/event-bus/implementations/_shared/test-utilities/event-bus-adapter.test-suite.d.ts +17 -1
- package/dist/types/event-bus/implementations/event-bus/event-bus-manager.d.ts +9 -6
- package/dist/types/serializer/contracts/serializer.contract.d.ts +0 -3
- package/dist/types/storage/contracts/storage-adapter.contract.d.ts +1 -18
- package/dist/types/storage/contracts/storage-events.contract.d.ts +1 -0
- package/dist/types/storage/contracts/storage-manager.contract.d.ts +87 -6
- package/dist/types/storage/contracts/storage.contract.d.ts +41 -33
- package/dist/types/storage/implementations/_shared/test-utilities/storage-adapter.test-suite.d.ts +18 -2
- package/dist/types/storage/implementations/storage/storage-manager.d.ts +12 -6
- package/dist/types/storage/implementations/storage/with-event-storage-adapter.d.ts +1 -1
- package/package.json +1 -1
|
@@ -8,12 +8,6 @@ export type AsyncCollapse<TValue> = TValue extends Array<infer TItem> | Iterable
|
|
|
8
8
|
/**
|
|
9
9
|
* The <i>IAsyncCollection</i> contract offers a fluent and efficient approach to working with {@link AsyncIterable} objects.
|
|
10
10
|
* <i>IAsyncCollection</i> is immutable.
|
|
11
|
-
* @throws {CollectionError} {@link CollectionError}
|
|
12
|
-
* @throws {UnexpectedCollectionError}
|
|
13
|
-
* @throws {ItemNotFoundCollectionError}
|
|
14
|
-
* @throws {MultipleItemsFoundCollectionError}
|
|
15
|
-
* @throws {TypeCollectionError}
|
|
16
|
-
* @throws {EmptyCollectionError}
|
|
17
11
|
* @group Contracts
|
|
18
12
|
*/
|
|
19
13
|
export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
@@ -36,47 +30,56 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
36
30
|
/**
|
|
37
31
|
* The <i>filter</i> method filters the collection using <i>predicateFn</i>, keeping only those items that pass <i>predicateFn</i>.
|
|
38
32
|
* @example
|
|
33
|
+
* ```ts
|
|
39
34
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
40
35
|
*
|
|
41
36
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4, 5, 6]);
|
|
42
37
|
* const filtered = collection.filter(item => 2 < item && item < 5);
|
|
43
38
|
* await filtered.toArray();
|
|
44
39
|
* // [3, 4]
|
|
40
|
+
* ```
|
|
45
41
|
*/
|
|
46
42
|
filter<TOutput extends TInput>(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>, TOutput>): IAsyncCollection<TOutput>;
|
|
47
43
|
/**
|
|
48
44
|
* The <i>reject</i> method filters the collection using <i>predicateFn</i>, keeping only those items that not pass <i>predicateFn</i>.
|
|
49
45
|
* @example
|
|
46
|
+
* ```ts
|
|
50
47
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
51
48
|
*
|
|
52
49
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4, 5, 6]);
|
|
53
50
|
* const filtered = collection.reject(item => 2 < item && item < 5);
|
|
54
51
|
* await filtered.toArray();
|
|
55
52
|
* // [1, 2, 5, 6]
|
|
53
|
+
* ```
|
|
56
54
|
*/
|
|
57
55
|
reject<TOutput extends TInput>(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>, TOutput>): IAsyncCollection<Exclude<TInput, TOutput>>;
|
|
58
56
|
/**
|
|
59
57
|
* The <i>map</i> method iterates through the collection and passes each item to <i>mapFn</i>.
|
|
60
58
|
* The <i>mapFn</i> is free to modify the item and return it, thus forming a new collection of modified items.
|
|
61
59
|
* @example
|
|
60
|
+
* ```ts
|
|
62
61
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
63
62
|
*
|
|
64
63
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]);
|
|
65
64
|
* const mapped = collection.map(item => item * 2);
|
|
66
65
|
* await mapped.toArray();
|
|
67
66
|
* // [2, 4, 6, 8, 10]
|
|
67
|
+
* ```
|
|
68
68
|
*/
|
|
69
69
|
map<TOutput>(mapFn: AsyncMap<TInput, IAsyncCollection<TInput>, TOutput>): IAsyncCollection<TOutput>;
|
|
70
70
|
/**
|
|
71
71
|
* The <i>reduce</i> method executes <i> reduceFn </i> function on each item of the array, passing in the return value from the calculation on the preceding item.
|
|
72
72
|
* The final result of running the reducer across all items of the array is a single value.
|
|
73
73
|
* @example
|
|
74
|
+
* ```ts
|
|
74
75
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
75
76
|
*
|
|
76
77
|
* const collection = new AsyncIterableCollection([1, 2, 3]);
|
|
77
78
|
* await collection.reduce((sum, item) => sum + item);
|
|
78
79
|
* // 6
|
|
80
|
+
* ```
|
|
79
81
|
* @example
|
|
82
|
+
* ```ts
|
|
80
83
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
81
84
|
*
|
|
82
85
|
* const collection = new AsyncIterableCollection(["a", "b", "c"]);
|
|
@@ -88,6 +91,7 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
88
91
|
* {} as Record<number, string>
|
|
89
92
|
* );
|
|
90
93
|
* // { 0: "a", 1: "b", 2: "c" }
|
|
94
|
+
* ```
|
|
91
95
|
*/
|
|
92
96
|
reduce(reduceFn: AsyncReduce<TInput, IAsyncCollection<TInput>, TInput>): PromiseLike<TInput>;
|
|
93
97
|
reduce(reduceFn: AsyncReduce<TInput, IAsyncCollection<TInput>, TInput>, initialValue: TInput): PromiseLike<TInput>;
|
|
@@ -96,72 +100,85 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
96
100
|
* The <i>join</i> method joins the collection's items with <i> separator </i>. An error will be thrown when if a none string item is encounterd.
|
|
97
101
|
* @throws {TypeCollectionError}
|
|
98
102
|
* @example
|
|
103
|
+
* ```ts
|
|
99
104
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
100
105
|
*
|
|
101
106
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
102
107
|
* await collection.map(item => item.toString()).join();
|
|
103
108
|
* // "1,2,3,4"
|
|
109
|
+
* ```
|
|
104
110
|
* @example
|
|
111
|
+
* ```ts
|
|
105
112
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
106
113
|
*
|
|
107
114
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
108
115
|
* await collection.map(item => item.toString()).join("_");
|
|
109
116
|
* // "1_2_3_4"
|
|
117
|
+
* ```
|
|
110
118
|
*/
|
|
111
119
|
join(separator?: string): PromiseLike<Extract<TInput, string>>;
|
|
112
120
|
/**
|
|
113
121
|
* The <i>collapse</i> method collapses a collection of iterables into a single, flat collection.
|
|
114
122
|
* @example
|
|
123
|
+
* ```ts
|
|
115
124
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
116
125
|
*
|
|
117
126
|
* const collection = new AsyncIterableCollection([[1, 2], [3, 4]]);
|
|
118
127
|
* const collapsed = collection.collapse();
|
|
119
128
|
* await collapsed.toArray();
|
|
120
129
|
* // [1, 2, 3, 4]
|
|
130
|
+
* ```
|
|
121
131
|
*/
|
|
122
132
|
collapse(): IAsyncCollection<AsyncCollapse<TInput>>;
|
|
123
133
|
/**
|
|
124
134
|
* The <i>flatMap</i> method returns a new array formed by applying <i>mapFn</i> to each item of the array, and then collapses the result by one level.
|
|
125
135
|
* It is identical to a <i>map</i> method followed by a <i>collapse</i> method.
|
|
126
136
|
* @example
|
|
137
|
+
* ```ts
|
|
127
138
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
128
139
|
*
|
|
129
140
|
* const collection = new AsyncIterableCollection([["a", "b"], ["c", "d"]]).flatMap(item => [item.length, ...item]);
|
|
130
141
|
* await collection.toArray();
|
|
131
142
|
* // [2, "a", "b", 2, "c", "d"]
|
|
143
|
+
* ```
|
|
132
144
|
*/
|
|
133
145
|
flatMap<TOutput>(mapFn: AsyncMap<TInput, IAsyncCollection<TInput>, Iterable<TOutput>>): IAsyncCollection<TOutput>;
|
|
134
146
|
/**
|
|
135
147
|
* The <i>change</i> method changes only the items that passes <i>predicateFn</i> using <i>mapFn</i>.
|
|
136
148
|
* @example
|
|
149
|
+
* ```ts
|
|
137
150
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
138
151
|
*
|
|
139
152
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]);
|
|
140
153
|
* const newCollection = collection.change(item => item % 2 === 0, item => item * 2);
|
|
141
154
|
* await newCollection.toArray();
|
|
142
155
|
* // [1, 4, 3, 8, 5]
|
|
156
|
+
* ```
|
|
143
157
|
*/
|
|
144
158
|
change<TFilterOutput extends TInput, TMapOutput>(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>, TFilterOutput>, mapFn: AsyncMap<TFilterOutput, IAsyncCollection<TInput>, TMapOutput>): IAsyncCollection<ChangendItem<TInput, TFilterOutput, TMapOutput>>;
|
|
145
159
|
/**
|
|
146
160
|
* The <i>page</i> method returns a new collection containing the items that would be present on <i> page </i> with custom <i> pageSize </i>.
|
|
147
161
|
* @example
|
|
162
|
+
* ```ts
|
|
148
163
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
149
164
|
*
|
|
150
165
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
|
151
166
|
* const page = collection.page(2, 3);
|
|
152
167
|
* await page.toArray();
|
|
153
168
|
* // [4, 5, 6]
|
|
169
|
+
* ```
|
|
154
170
|
*/
|
|
155
171
|
page(page: number, pageSize: number): IAsyncCollection<TInput>;
|
|
156
172
|
/**
|
|
157
173
|
* The <i>sum</i> method returns the sum of all items in the collection. If the collection includes other than number items an error will be thrown.
|
|
158
174
|
* @example
|
|
175
|
+
* ```ts
|
|
159
176
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
160
177
|
*
|
|
161
178
|
* const collection = new AsyncIterableCollection([1, 2, 3]);
|
|
162
179
|
* await collection.sum();
|
|
163
180
|
* // 6
|
|
164
|
-
*
|
|
181
|
+
* ```
|
|
165
182
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
166
183
|
* @throws {TypeCollectionError} {@link TypeCollectionError}
|
|
167
184
|
* @throws {EmptyCollectionError} {@link EmptyCollectionError}
|
|
@@ -170,12 +187,13 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
170
187
|
/**
|
|
171
188
|
* The <i>average</i> method returns the average of all items in the collection. If the collection includes other than number items an error will be thrown.
|
|
172
189
|
* @example
|
|
190
|
+
* ```ts
|
|
173
191
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
174
192
|
*
|
|
175
193
|
* const collection = new AsyncIterableCollection([1, 2, 3]);
|
|
176
194
|
* await collection.average();
|
|
177
195
|
* // 2
|
|
178
|
-
*
|
|
196
|
+
* ```
|
|
179
197
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
180
198
|
* @throws {TypeCollectionError} {@link TypeCollectionError}
|
|
181
199
|
* @throws {EmptyCollectionError} {@link EmptyCollectionError}
|
|
@@ -184,12 +202,13 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
184
202
|
/**
|
|
185
203
|
* The <i>median</i> method returns the median of all items in the collection. If the collection includes other than number items an error will be thrown.
|
|
186
204
|
* @example
|
|
205
|
+
* ```ts
|
|
187
206
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
188
207
|
*
|
|
189
208
|
* const collection = new AsyncIterableCollection([1, 2, 3]);
|
|
190
209
|
* await collection.median();
|
|
191
210
|
* // 2
|
|
192
|
-
*
|
|
211
|
+
* ```
|
|
193
212
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
194
213
|
* @throws {TypeCollectionError} {@link TypeCollectionError}
|
|
195
214
|
* @throws {EmptyCollectionError} {@link EmptyCollectionError}
|
|
@@ -198,12 +217,13 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
198
217
|
/**
|
|
199
218
|
* The <i>min</i> method returns the min of all items in the collection. If the collection includes other than number items an error will be thrown.
|
|
200
219
|
* @example
|
|
220
|
+
* ```ts
|
|
201
221
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
202
222
|
*
|
|
203
223
|
* const collection = new AsyncIterableCollection([1, 2, 3]);
|
|
204
224
|
* await collection.min();
|
|
205
225
|
* // 1
|
|
206
|
-
*
|
|
226
|
+
* ```
|
|
207
227
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
208
228
|
* @throws {TypeCollectionError} {@link TypeCollectionError}
|
|
209
229
|
* @throws {EmptyCollectionError} {@link EmptyCollectionError}
|
|
@@ -212,12 +232,13 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
212
232
|
/**
|
|
213
233
|
* The <i>max</i> method returns the max of all items in the collection. If the collection includes other than number items an error will be thrown.
|
|
214
234
|
* @example
|
|
235
|
+
* ```ts
|
|
215
236
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
216
237
|
*
|
|
217
238
|
* const collection = new AsyncIterableCollection([1, 2, 3]);
|
|
218
239
|
* await collection.max();
|
|
219
240
|
* // 3
|
|
220
|
-
*
|
|
241
|
+
* ```
|
|
221
242
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
222
243
|
* @throws {TypeCollectionError} {@link TypeCollectionError}
|
|
223
244
|
* @throws {EmptyCollectionError} {@link EmptyCollectionError}
|
|
@@ -226,12 +247,13 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
226
247
|
/**
|
|
227
248
|
* The <i>percentage</i> method may be used to quickly determine the percentage of items in the collection that pass <i>predicateFn</i>.
|
|
228
249
|
* @example
|
|
250
|
+
* ```ts
|
|
229
251
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
230
252
|
*
|
|
231
253
|
* const collection = new AsyncIterableCollection([1, 1, 2, 2, 2, 3]);
|
|
232
254
|
* await collection.percentage(value => value === 1);
|
|
233
255
|
* // 33.333
|
|
234
|
-
*
|
|
256
|
+
* ```
|
|
235
257
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
236
258
|
* @throws {EmptyCollectionError} {@link EmptyCollectionError}
|
|
237
259
|
*/
|
|
@@ -239,100 +261,117 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
239
261
|
/**
|
|
240
262
|
* The <i>some</i> method determines whether at least one item in the collection matches <i>predicateFn</i>.
|
|
241
263
|
* @example
|
|
264
|
+
* ```ts
|
|
242
265
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
243
266
|
*
|
|
244
267
|
* const collection = new AsyncIterableCollection([0, 1, 2, 3, 4, 5]);
|
|
245
268
|
* await collection.some(item => item === 1);
|
|
246
269
|
* // true
|
|
247
|
-
*
|
|
270
|
+
* ```
|
|
248
271
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
249
272
|
*/
|
|
250
273
|
some<TOutput extends TInput>(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>, TOutput>): PromiseLike<boolean>;
|
|
251
274
|
/**
|
|
252
275
|
* The <i>every</i> method determines whether all items in the collection matches <i>predicateFn</i>.
|
|
253
276
|
* @example
|
|
277
|
+
* ```ts
|
|
254
278
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
255
279
|
*
|
|
256
280
|
* const collection = new AsyncIterableCollection([0, 1, 2, 3, 4, 5]);
|
|
257
281
|
* await collection.every(item => item < 6);
|
|
258
282
|
* // true
|
|
259
|
-
*
|
|
283
|
+
* ```
|
|
260
284
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
261
285
|
*/
|
|
262
286
|
every<TOutput extends TInput>(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>, TOutput>): PromiseLike<boolean>;
|
|
263
287
|
/**
|
|
264
288
|
* The <i>take</i> method takes the first <i>limit</i> items.
|
|
265
289
|
* @example
|
|
290
|
+
* ```ts
|
|
266
291
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
267
292
|
*
|
|
268
293
|
* const collection = new AsyncIterableCollection([0, 1, 2, 3, 4, 5]);
|
|
269
294
|
* const chunk = collection.take(3);
|
|
270
295
|
* await chunk.toArray();
|
|
271
296
|
* // [0, 1, 2]
|
|
297
|
+
* ```
|
|
272
298
|
* @example
|
|
299
|
+
* ```ts
|
|
273
300
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
274
301
|
*
|
|
275
302
|
* const collection = new AsyncIterableCollection([0, 1, 2, 3, 4, 5]);
|
|
276
303
|
* const chunk = collection.take(-2);
|
|
277
304
|
* await chunk.toArray();
|
|
278
305
|
* // [0, 1, 2, 3]
|
|
306
|
+
* ```
|
|
279
307
|
*/
|
|
280
308
|
take(limit: number): IAsyncCollection<TInput>;
|
|
281
309
|
/**
|
|
282
310
|
* The <i>takeUntil</i> method takes items until <i>predicateFn</i> returns true.
|
|
283
311
|
* @example
|
|
312
|
+
* ```ts
|
|
284
313
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
285
314
|
*
|
|
286
315
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
287
316
|
* const chunk = collection.takeUntil(item => item >= 3);
|
|
288
317
|
* await chunk.toArray();
|
|
289
318
|
* // [1, 2]
|
|
319
|
+
* ```
|
|
290
320
|
*/
|
|
291
321
|
takeUntil(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): IAsyncCollection<TInput>;
|
|
292
322
|
/**
|
|
293
323
|
* The <i>takeWhile</i> method takes items until <i>predicateFn</i> returns false.
|
|
294
324
|
* @example
|
|
325
|
+
* ```ts
|
|
295
326
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
296
327
|
*
|
|
297
328
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
298
329
|
* const chunk = collection.takeWhile(item => item < 4);
|
|
299
330
|
* await chunk.toArray();
|
|
300
331
|
* // [1, 2, 3]
|
|
332
|
+
* ```
|
|
301
333
|
*/
|
|
302
334
|
takeWhile(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): IAsyncCollection<TInput>;
|
|
303
335
|
/**
|
|
304
336
|
* The <i>skip</i> method skips the first <i>offset</i> items.
|
|
305
337
|
* @example
|
|
338
|
+
* ```ts
|
|
306
339
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
307
340
|
*
|
|
308
341
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]).skip(4);
|
|
309
342
|
* await collection.toArray();
|
|
310
343
|
* // [5, 6, 7, 8, 9, 10]
|
|
344
|
+
* ```
|
|
311
345
|
*/
|
|
312
346
|
skip(offset: number): IAsyncCollection<TInput>;
|
|
313
347
|
/**
|
|
314
348
|
* The <i>skipUntil</i> method skips items until <i>predicateFn</i> returns true.
|
|
315
349
|
* @example
|
|
350
|
+
* ```ts
|
|
316
351
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
317
352
|
*
|
|
318
353
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]).skipUntil(item => item >= 3);
|
|
319
354
|
* await collection.toArray();
|
|
320
355
|
* // [3, 4]
|
|
356
|
+
* ```
|
|
321
357
|
*/
|
|
322
358
|
skipUntil(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): IAsyncCollection<TInput>;
|
|
323
359
|
/**
|
|
324
360
|
* The <i>skipWhile</i> method skips items until <i>predicateFn</i> returns false.
|
|
325
361
|
* @example
|
|
362
|
+
* ```ts
|
|
326
363
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
327
364
|
*
|
|
328
365
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]).skipWhile(item => item <= 3);
|
|
329
366
|
* await collection.toArray();
|
|
330
367
|
* // [4]
|
|
368
|
+
* ```
|
|
331
369
|
*/
|
|
332
370
|
skipWhile(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): IAsyncCollection<TInput>;
|
|
333
371
|
/**
|
|
334
372
|
* The <i>when</i> method will execute <i>callback</i> when <i>condition</i> evaluates to true.
|
|
335
373
|
* @example
|
|
374
|
+
* ```ts
|
|
336
375
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
337
376
|
*
|
|
338
377
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4])
|
|
@@ -340,29 +379,35 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
340
379
|
* .when(false, collection => collection.append([20]));
|
|
341
380
|
* await collection.toArray();
|
|
342
381
|
* // [1, 2, 3, 4, -3]
|
|
382
|
+
* ```
|
|
343
383
|
*/
|
|
344
384
|
when<TExtended = TInput>(condition: boolean, callback: AsyncModifier<IAsyncCollection<TInput>, IAsyncCollection<TExtended>>): IAsyncCollection<TInput | TExtended>;
|
|
345
385
|
/**
|
|
346
386
|
* The <i>whenEmpty</i> method will execute <i>callback</i> when the collection is empty.
|
|
347
387
|
* @example
|
|
388
|
+
* ```ts
|
|
348
389
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
349
390
|
*
|
|
350
391
|
* const collection = new AsyncIterableCollection([])
|
|
351
392
|
* .whenEmpty(collection => collection.append([-3]))
|
|
352
393
|
* await collection.toArray();
|
|
353
394
|
* // [-3]
|
|
395
|
+
* ```
|
|
354
396
|
* @example
|
|
397
|
+
* ```ts
|
|
355
398
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
356
399
|
*
|
|
357
400
|
* const collection = new AsyncIterableCollection([1])
|
|
358
401
|
* .whenEmpty(collection => collection.append([-3]))
|
|
359
402
|
* await collection.toArray();
|
|
360
403
|
* // [1]
|
|
404
|
+
* ```
|
|
361
405
|
*/
|
|
362
406
|
whenEmpty<TExtended = TInput>(callback: AsyncModifier<IAsyncCollection<TInput>, IAsyncCollection<TExtended>>): IAsyncCollection<TInput | TExtended>;
|
|
363
407
|
/**
|
|
364
408
|
* The <i>whenNot</i> method will execute <i>callback</i> when <i>condition</i> evaluates to false.
|
|
365
409
|
* @example
|
|
410
|
+
* ```ts
|
|
366
411
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
367
412
|
*
|
|
368
413
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4])
|
|
@@ -370,30 +415,36 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
370
415
|
* .whenNot(false, collection => collection.append([20]));
|
|
371
416
|
* await collection.toArray();
|
|
372
417
|
* // [1, 2, 3, 4, 20]
|
|
418
|
+
* ```
|
|
373
419
|
*/
|
|
374
420
|
whenNot<TExtended = TInput>(condition: boolean, callback: AsyncModifier<IAsyncCollection<TInput>, IAsyncCollection<TExtended>>): IAsyncCollection<TInput | TExtended>;
|
|
375
421
|
/**
|
|
376
422
|
* The <i>whenNotEmpty</i> method will execute <i>callback</i> when the collection is not empty.
|
|
377
423
|
* @example
|
|
424
|
+
* ```ts
|
|
378
425
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
379
426
|
*
|
|
380
427
|
* const collection = new AsyncIterableCollection([])
|
|
381
428
|
* .whenNotEmpty(collection => collection.append([-3]))
|
|
382
429
|
* await collection.toArray();
|
|
383
430
|
* // []
|
|
431
|
+
* ```
|
|
384
432
|
* @example
|
|
433
|
+
* ```ts
|
|
385
434
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
386
435
|
*
|
|
387
436
|
* const collection = new AsyncIterableCollection([1])
|
|
388
437
|
* .whenNotEmpty(collection => collection.append([-3]))
|
|
389
438
|
* await collection.toArray();
|
|
390
439
|
* // [1, -3]
|
|
440
|
+
* ```
|
|
391
441
|
*/
|
|
392
442
|
whenNotEmpty<TExtended = TInput>(callback: AsyncModifier<IAsyncCollection<TInput>, IAsyncCollection<TExtended>>): IAsyncCollection<TInput | TExtended>;
|
|
393
443
|
/**
|
|
394
444
|
* The <i>pipe</i> method passes the orignal collection to <i>callback</i> and returns the result from <i>callback</i>.
|
|
395
445
|
* This method is useful when you want compose multiple smaller functions.
|
|
396
446
|
* @example
|
|
447
|
+
* ```ts
|
|
397
448
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
398
449
|
*
|
|
399
450
|
* const collection = new AsyncIterableCollection([1, "2", "a", 1, 3, {}]);
|
|
@@ -410,11 +461,13 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
410
461
|
* const piped = await collection.pipe(toNbrs).then(nbrToStr);
|
|
411
462
|
* console.log(piped);
|
|
412
463
|
* // [ 1, 2, 1, 3 ]
|
|
464
|
+
* ```
|
|
413
465
|
*/
|
|
414
466
|
pipe<TOutput = TInput>(callback: AsyncTransform<IAsyncCollection<TInput>, TOutput>): PromiseLike<TOutput>;
|
|
415
467
|
/**
|
|
416
468
|
* The <i>tap</i> method passes a copy of the original collection to <i>callback</i>, allowing you to do something with the items while not affecting the original collection.
|
|
417
469
|
* @example
|
|
470
|
+
* ```ts
|
|
418
471
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
419
472
|
*
|
|
420
473
|
* const collection = await new AsyncIterableCollection([1, 2, 3, 4, 5, 6])
|
|
@@ -425,24 +478,28 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
425
478
|
* })
|
|
426
479
|
* .toArray();
|
|
427
480
|
* // [1, 2, 3, 4, 5, 6]
|
|
481
|
+
* ```
|
|
428
482
|
*/
|
|
429
483
|
tap(callback: AsyncTap<IAsyncCollection<TInput>>): IAsyncCollection<TInput>;
|
|
430
484
|
/**
|
|
431
485
|
* The <i>chunk</i> method breaks the collection into multiple, smaller collections of size <i>chunkSize</i>.
|
|
432
486
|
* If <i>chunkSize</i> is not divisible with total number of items then the last chunk will contain the remaining items.
|
|
433
487
|
* @example
|
|
488
|
+
* ```ts
|
|
434
489
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
435
490
|
*
|
|
436
491
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4, 5, 6, 7]);
|
|
437
492
|
* const chunks = collection.chunk(4);
|
|
438
493
|
* await chunks.map(chunk => chunk.toArray()).toArray();
|
|
439
494
|
* // [[1, 2, 3, 4], [5, 6, 7]]
|
|
495
|
+
* ```
|
|
440
496
|
*/
|
|
441
497
|
chunk(chunkSize: number): IAsyncCollection<IAsyncCollection<TInput>>;
|
|
442
498
|
/**
|
|
443
499
|
* The <i>chunkWhile</i> method breaks the collection into multiple, smaller collections based on the evaluation of <i>predicateFn</i>.
|
|
444
500
|
* The chunk variable passed to the <i>predicateFn</i> may be used to inspect the previous item.
|
|
445
501
|
* @example
|
|
502
|
+
* ```ts
|
|
446
503
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
447
504
|
*
|
|
448
505
|
* const collection = new AsyncIterableCollection("AABBCCCD");
|
|
@@ -451,25 +508,31 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
451
508
|
* });
|
|
452
509
|
* await chunks.map(chunk => chunk.toArray()).toArray();
|
|
453
510
|
* // [["A", "A"], ["B", "B"], ["C", "C", "C"], ["D"]]
|
|
511
|
+
* ```
|
|
454
512
|
*/
|
|
455
513
|
chunkWhile(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): IAsyncCollection<IAsyncCollection<TInput>>;
|
|
456
514
|
/**
|
|
457
515
|
* The <i>split</i> method breaks a collection evenly into <i>chunkAmount</i> of chunks.
|
|
458
516
|
* @example
|
|
517
|
+
* ```ts
|
|
459
518
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
460
519
|
*
|
|
461
520
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]);
|
|
462
521
|
* const chunks = collection.split(3);
|
|
463
522
|
* await chunks.map(chunk => chunk.toArray()).toArray();
|
|
464
523
|
* // [[1, 2], [3, 4], [5]]
|
|
524
|
+
* ```
|
|
465
525
|
* @example
|
|
526
|
+
* ```ts
|
|
466
527
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
467
528
|
*
|
|
468
529
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4, 5, 6]);
|
|
469
530
|
* const chunks = collection.split(3);
|
|
470
531
|
* await chunks.map(chunk => chunk.toArray()).toArray();
|
|
471
532
|
* // [[1, 2], [3, 4], [5, 6]]
|
|
533
|
+
* ```
|
|
472
534
|
* @example
|
|
535
|
+
* ```ts
|
|
473
536
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
474
537
|
*
|
|
475
538
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4, 5, 6, 7]);
|
|
@@ -481,29 +544,34 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
481
544
|
/**
|
|
482
545
|
* The <i>partition</i> method is used to separate items that pass <i>predicateFn</i> from those that do not.
|
|
483
546
|
* @example
|
|
547
|
+
* ```ts
|
|
484
548
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
485
549
|
*
|
|
486
550
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4, 5, 6]);
|
|
487
551
|
* const chunks = collection.partition(item => item < 3);
|
|
488
552
|
* await chunks.map(chunk => chunk.toArray()).toArray();
|
|
489
553
|
* // [[1, 2], [3, 4, 5, 6]]
|
|
554
|
+
* ```
|
|
490
555
|
*/
|
|
491
556
|
partition(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): IAsyncCollection<IAsyncCollection<TInput>>;
|
|
492
557
|
/**
|
|
493
558
|
* The <i>sliding</i> method returns a new collection of chunks representing a "sliding window" view of the items in the collection.
|
|
494
559
|
* @example
|
|
560
|
+
* ```ts
|
|
495
561
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
496
562
|
*
|
|
497
563
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4, 5])
|
|
498
564
|
* const chunks = collection.sliding(2);
|
|
499
565
|
* await chunks.map(chunk => chunk.toArray()).toArray();
|
|
500
566
|
* // [[1, 2], [2, 3], [3, 4], [4, 5]]
|
|
567
|
+
* ```
|
|
501
568
|
*/
|
|
502
569
|
sliding(chunkSize: number, step?: number): IAsyncCollection<IAsyncCollection<TInput>>;
|
|
503
570
|
/**
|
|
504
571
|
* The <i>groupBy</i> method groups the collection's items by <i> selectFn </i>.
|
|
505
572
|
* By default the equality check occurs on the item.
|
|
506
573
|
* @example
|
|
574
|
+
* ```ts
|
|
507
575
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
508
576
|
*
|
|
509
577
|
* const collection = new AsyncIterableCollection(["a", "a", "a", "b", "b", "c"]);
|
|
@@ -525,7 +593,9 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
525
593
|
* // ["c"]
|
|
526
594
|
* // ]
|
|
527
595
|
* // ]
|
|
596
|
+
* ```
|
|
528
597
|
* @example
|
|
598
|
+
* ```ts
|
|
529
599
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
530
600
|
*
|
|
531
601
|
* const collection = new AsyncIterableCollection(["alice@gmail.com", "bob@yahoo.com", "carlos@gmail.com"]);
|
|
@@ -543,12 +613,14 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
543
613
|
* // ["bob@yahoo.com"]
|
|
544
614
|
* // ]
|
|
545
615
|
* // ]
|
|
616
|
+
* ```
|
|
546
617
|
*/
|
|
547
618
|
groupBy<TOutput = TInput>(selectFn?: AsyncMap<TInput, IAsyncCollection<TInput>, TOutput>): IAsyncCollection<RecordItem<TOutput, IAsyncCollection<TInput>>>;
|
|
548
619
|
/**
|
|
549
620
|
* The <i>countBy</i> method counts the occurrences of values in the collection by <i> selectFn </i>.
|
|
550
621
|
* By default the equality check occurs on the item.
|
|
551
622
|
* @example
|
|
623
|
+
* ```ts
|
|
552
624
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
553
625
|
*
|
|
554
626
|
* const collection = new AsyncIterableCollection(["a", "a", "a", "b", "b", "c"]);
|
|
@@ -561,7 +633,9 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
561
633
|
* // ["b", 2],
|
|
562
634
|
* // ["c", 1]
|
|
563
635
|
* // ]
|
|
636
|
+
* ```
|
|
564
637
|
* @example
|
|
638
|
+
* ```ts
|
|
565
639
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
566
640
|
*
|
|
567
641
|
* const collection = new AsyncIterableCollection(["alice@gmail.com", "bob@yahoo.com", "carlos@gmail.com"]);
|
|
@@ -572,18 +646,22 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
572
646
|
* // ["gmail.com", 2],
|
|
573
647
|
* // ["yahoo.com", 1]
|
|
574
648
|
* // ]
|
|
649
|
+
* ```
|
|
575
650
|
*/
|
|
576
651
|
countBy<TOutput = TInput>(selectFn?: AsyncMap<TInput, IAsyncCollection<TInput>, TOutput>): IAsyncCollection<RecordItem<TOutput, number>>;
|
|
577
652
|
/**
|
|
578
653
|
* The <i>unique</i> method removes all duplicate values from the collection by <i> selectFn </i>.
|
|
579
654
|
* By default the equality check occurs on the item.
|
|
580
655
|
* @example
|
|
656
|
+
* ```ts
|
|
581
657
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
582
658
|
*
|
|
583
659
|
* const collection = new AsyncIterableCollection([1, 1, 2, 2, 3, 4, 2]);
|
|
584
660
|
* await collection.unique().toArray();
|
|
585
661
|
* // [1, 2, 3, 4]
|
|
662
|
+
* ```
|
|
586
663
|
* @example
|
|
664
|
+
* ```ts
|
|
587
665
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
588
666
|
*
|
|
589
667
|
* const collection = new AsyncIterableCollection([
|
|
@@ -600,19 +678,23 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
600
678
|
* // { name: "iPhone 6", brand: "Apple", type: "phone" },
|
|
601
679
|
* // { name: "Galaxy S6", brand: "Samsung", type: "phone" },
|
|
602
680
|
* // ]
|
|
681
|
+
* ```
|
|
603
682
|
*/
|
|
604
683
|
unique<TOutput = TInput>(selectFn?: AsyncMap<TInput, IAsyncCollection<TInput>, TOutput>): IAsyncCollection<TInput>;
|
|
605
684
|
/**
|
|
606
685
|
* The <i>difference</i> method will return the values in the original collection that are not present in <i>iterable</i>.
|
|
607
686
|
* By default the equality check occurs on the item.
|
|
608
687
|
* @example
|
|
688
|
+
* ```ts
|
|
609
689
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
610
690
|
*
|
|
611
691
|
* const collection = new AsyncIterableCollection([1, 2, 2, 3, 4, 5]);
|
|
612
692
|
* const difference = collection.difference([2, 4, 6, 8]);
|
|
613
693
|
* await difference.toArray();
|
|
614
694
|
* // [1, 3, 5]
|
|
695
|
+
* ```
|
|
615
696
|
* @example
|
|
697
|
+
* ```ts
|
|
616
698
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
617
699
|
*
|
|
618
700
|
* const collection = new AsyncIterableCollection([
|
|
@@ -634,23 +716,27 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
634
716
|
* // { name: "iPhone 5", brand: "Apple", type: "phone" },
|
|
635
717
|
* // { name: "Galaxy S6", brand: "Samsung", type: "phone" },
|
|
636
718
|
* // ]
|
|
719
|
+
* ```
|
|
637
720
|
*/
|
|
638
721
|
difference<TOutput = TInput>(iterable: AsyncIterableValue<TInput>, selectFn?: AsyncMap<TInput, IAsyncCollection<TInput>, TOutput>): IAsyncCollection<TInput>;
|
|
639
722
|
/**
|
|
640
723
|
* The <i>repeat</i> method will repeat the original collection <i>amount</i> times.
|
|
641
724
|
* @example
|
|
725
|
+
* ```ts
|
|
642
726
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
643
727
|
*
|
|
644
728
|
* const collection = new AsyncIterableCollection([1, 2, 3]);
|
|
645
729
|
* const newCollection = collection.repeat(3);
|
|
646
730
|
* await newCollection.toArray();
|
|
647
731
|
* // [1, 2, 3, 1, 2, 3, 1, 2, 3]
|
|
732
|
+
* ```
|
|
648
733
|
*/
|
|
649
734
|
repeat(amount: number): IAsyncCollection<TInput>;
|
|
650
735
|
/**
|
|
651
736
|
* The <i>padStart</i> method pads this collection with <i>fillItems</i> until the resulting collection size reaches <i>maxLength</i>.
|
|
652
737
|
* The padding is applied from the start of this collection.
|
|
653
738
|
* @example
|
|
739
|
+
* ```ts
|
|
654
740
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
655
741
|
*
|
|
656
742
|
* await new AsyncIterableCollection("abc").padStart(10, "foo").join("");
|
|
@@ -664,12 +750,14 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
664
750
|
*
|
|
665
751
|
* await new AsyncIterableCollection("abc").padStart(1, "_").join("");
|
|
666
752
|
* // "abc"
|
|
753
|
+
* ```
|
|
667
754
|
*/
|
|
668
755
|
padStart<TExtended = TInput>(maxLength: number, fillItems: AsyncIterableValue<TExtended>): IAsyncCollection<TInput | TExtended>;
|
|
669
756
|
/**
|
|
670
757
|
* The <i>padEnd</i> method pads this collection with <i>fillItems</i> until the resulting collection size reaches <i>maxLength</i>.
|
|
671
758
|
* The padding is applied from the end of this collection.
|
|
672
759
|
* @example
|
|
760
|
+
* ```ts
|
|
673
761
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
674
762
|
*
|
|
675
763
|
* await new AsyncIterableCollection("abc").padEnd(10, "foo").join("");
|
|
@@ -683,92 +771,114 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
683
771
|
*
|
|
684
772
|
* await new AsyncIterableCollection("abc").padEnd(1, "_").join("");
|
|
685
773
|
* // "abc"
|
|
774
|
+
* ```
|
|
686
775
|
*/
|
|
687
776
|
padEnd<TExtended = TInput>(maxLength: number, fillItems: AsyncIterableValue<TExtended>): IAsyncCollection<TInput | TExtended>;
|
|
688
777
|
/**
|
|
689
778
|
* The <i>slice</i> method creates porition of the original collection selected from <i>start</i> and <i>end</i>
|
|
690
779
|
* where <i>start</i> and <i>end</i> (end not included) represent the index of items in the collection.
|
|
691
780
|
* @example
|
|
781
|
+
* ```ts
|
|
692
782
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
693
783
|
*
|
|
694
784
|
* const collection = new AsyncIterableCollection(["a", "b", "c", "d", "e", "f"]);
|
|
695
785
|
* await collection.slice(3).toArray();
|
|
696
786
|
* // ["d", "e", "f"]
|
|
787
|
+
* ```
|
|
697
788
|
* @example
|
|
789
|
+
* ```ts
|
|
698
790
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
699
791
|
*
|
|
700
792
|
* const collection = new AsyncIterableCollection(["a", "b", "c", "d", "e", "f"]);
|
|
701
793
|
* await collection.slice(undefined, 2).toArray();
|
|
702
794
|
* // ["a", "b"]
|
|
795
|
+
* ```
|
|
703
796
|
* @example
|
|
797
|
+
* ```ts
|
|
704
798
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
705
799
|
*
|
|
706
800
|
* const collection = new AsyncIterableCollection(["a", "b", "c", "d", "e", "f"]);
|
|
707
801
|
* await collection.slice(2, 5).toArray();
|
|
708
802
|
* // ["c", "d", "e"]
|
|
803
|
+
* ```
|
|
709
804
|
* @example
|
|
805
|
+
* ```ts
|
|
710
806
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
711
807
|
*
|
|
712
808
|
* const collection = new AsyncIterableCollection(["a", "b", "c", "d", "e", "f"]);
|
|
713
809
|
* await collection.slice(-2).toArray();
|
|
714
810
|
* // ["e", "f"]
|
|
811
|
+
* ```
|
|
715
812
|
* @example
|
|
813
|
+
* ```ts
|
|
716
814
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
717
815
|
*
|
|
718
816
|
* const collection = new AsyncIterableCollection(["a", "b", "c", "d", "e", "f"]);
|
|
719
817
|
* await collection.slice(undefined, -2).toArray();
|
|
720
818
|
* // ["a", "b", "c", "d"]
|
|
819
|
+
* ```
|
|
721
820
|
* @example
|
|
821
|
+
* ```ts
|
|
722
822
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
723
823
|
*
|
|
724
824
|
* const collection = new AsyncIterableCollection(["a", "b", "c", "d", "e", "f"]);
|
|
725
825
|
* await collection.slice(-4, -2).toArray();
|
|
726
826
|
* // ["c", "d"]
|
|
827
|
+
* ```
|
|
727
828
|
*/
|
|
728
829
|
slice(start?: number, end?: number): IAsyncCollection<TInput>;
|
|
729
830
|
/**
|
|
730
831
|
* The <i>prepend</i> method adds <i>iterable</i> to the beginning of the collection.
|
|
731
832
|
* @example
|
|
833
|
+
* ```ts
|
|
732
834
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
733
835
|
*
|
|
734
836
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]).prepend([-1, 20]);
|
|
735
837
|
* await collection.toArray();
|
|
736
838
|
* // [-1, 20, 1, 2, 3, 4, 5]
|
|
839
|
+
* ```
|
|
737
840
|
*/
|
|
738
841
|
prepend<TExtended = TInput>(iterable: AsyncIterableValue<TInput | TExtended>): IAsyncCollection<TInput | TExtended>;
|
|
739
842
|
/**
|
|
740
843
|
* The <i>append</i> method adds <i>iterable</i> to the end of the collection.
|
|
741
844
|
* @example
|
|
845
|
+
* ```ts
|
|
742
846
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
743
847
|
*
|
|
744
848
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]).append([-1, -2]);
|
|
745
849
|
* await collection.toArray();
|
|
746
850
|
* // [1, 2, 3, 4, 5, -1, -2,]
|
|
851
|
+
* ```
|
|
747
852
|
*/
|
|
748
853
|
append<TExtended = TInput>(iterable: AsyncIterableValue<TInput | TExtended>): IAsyncCollection<TInput | TExtended>;
|
|
749
854
|
/**
|
|
750
855
|
* The <i>insertBefore</i> method adds <i>iterable</i> before the first item that matches <i>predicateFn</i>.
|
|
751
856
|
* @example
|
|
857
|
+
* ```ts
|
|
752
858
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
753
859
|
*
|
|
754
860
|
* const collection = new AsyncIterableCollection([1, 2, 2, 3, 4, 5]).insertBefore(item => item === 2, [-1, 20]);
|
|
755
861
|
* await collection.toArray();
|
|
756
862
|
* // [1, -1, 20, 2, 2, 3, 4, 5]
|
|
863
|
+
* ```
|
|
757
864
|
*/
|
|
758
865
|
insertBefore<TExtended = TInput>(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>, iterable: AsyncIterableValue<TInput | TExtended>): IAsyncCollection<TInput | TExtended>;
|
|
759
866
|
/**
|
|
760
867
|
* The <i>insertAfter</i> method adds <i>iterable</i> after the first item that matches <i>predicateFn</i>.
|
|
761
868
|
* @example
|
|
869
|
+
* ```ts
|
|
762
870
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
763
871
|
*
|
|
764
872
|
* const collection = new AsyncIterableCollection([1, 2, 2, 3, 4, 5]).insertAfter(item => item === 2, [-1, 20]);
|
|
765
873
|
* await collection.toArray();
|
|
766
874
|
* // [1, 2, -1, 20, 2, 3, 4, 5]
|
|
875
|
+
* ```
|
|
767
876
|
*/
|
|
768
877
|
insertAfter<TExtended = TInput>(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>, iterable: AsyncIterableValue<TInput | TExtended>): IAsyncCollection<TInput | TExtended>;
|
|
769
878
|
/**
|
|
770
879
|
* The <i>crossJoin</i> method cross joins the collection's values among <i>iterables</i>, returning a Cartesian product with all possible permutations.
|
|
771
880
|
* @example
|
|
881
|
+
* ```ts
|
|
772
882
|
* import { ListCollection } from "@daiso-tech/core";;
|
|
773
883
|
*
|
|
774
884
|
* const collection = new ListCollection([1, 2]);
|
|
@@ -780,7 +890,9 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
780
890
|
* // [2, "a"],
|
|
781
891
|
* // [2, "b"],
|
|
782
892
|
* // ]
|
|
893
|
+
* ```
|
|
783
894
|
* @example
|
|
895
|
+
* ```ts
|
|
784
896
|
* import { ListCollection } from "@daiso-tech/core";;
|
|
785
897
|
*
|
|
786
898
|
* const collection = new ListCollection([1, 2]);
|
|
@@ -796,43 +908,53 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
796
908
|
* // [2, "b", "I"],
|
|
797
909
|
* // [2, "b", "II"],
|
|
798
910
|
* // ]
|
|
911
|
+
* ```
|
|
799
912
|
*/
|
|
800
913
|
crossJoin<TExtended>(iterable: AsyncIterableValue<TExtended>): IAsyncCollection<CrossJoinResult<TInput, TExtended>>;
|
|
801
914
|
/**
|
|
802
915
|
* The <i>zip</i> method merges together the values of <i>iterable</i> with the values of the collection at their corresponding index.
|
|
803
916
|
* The returned collection has size of the shortest collection.
|
|
804
917
|
* @example
|
|
918
|
+
* ```ts
|
|
805
919
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
806
920
|
*
|
|
807
921
|
* const collection = new AsyncIterableCollection(["Chair", "Desk"]);
|
|
808
922
|
* const zipped = collection.zip([100, 200]);
|
|
809
923
|
* await zipped.toArray();
|
|
810
924
|
* // [["Chair", 100], ["Desk", 200]]
|
|
925
|
+
* ```
|
|
811
926
|
* @example
|
|
927
|
+
* ```ts
|
|
812
928
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
813
929
|
*
|
|
814
930
|
* const collection = new AsyncIterableCollection(["Chair", "Desk", "Couch"]);
|
|
815
931
|
* const zipped = collection.zip([100, 200]);
|
|
816
932
|
* await zipped.toArray();
|
|
817
933
|
* // [["Chair", 100], ["Desk", 200]]
|
|
934
|
+
* ```
|
|
818
935
|
* @example
|
|
936
|
+
* ```ts
|
|
819
937
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
820
938
|
*
|
|
821
939
|
* const collection = new AsyncIterableCollection(["Chair", "Desk"]);
|
|
822
940
|
* const zipped = collection.zip([100, 200, 300]);
|
|
823
941
|
* await zipped.toArray();
|
|
824
942
|
* // [["Chair", 100], ["Desk", 200]]
|
|
943
|
+
* ```
|
|
825
944
|
*/
|
|
826
945
|
zip<TExtended>(iterable: AsyncIterableValue<TExtended>): IAsyncCollection<RecordItem<TInput, TExtended>>;
|
|
827
946
|
/**
|
|
828
947
|
* The <i>sort</i> method sorts the collection. You can provide a <i>comparator</i> function.
|
|
829
948
|
* @example
|
|
949
|
+
* ```ts
|
|
830
950
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
831
951
|
*
|
|
832
952
|
* const collection = new AsyncIterableCollection([-1, 2, 4, 3]);
|
|
833
953
|
* await collection.sort().toArray();
|
|
834
954
|
* // [-1, 2, 3, 4]
|
|
955
|
+
* ```
|
|
835
956
|
* @example
|
|
957
|
+
* ```ts
|
|
836
958
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
837
959
|
*
|
|
838
960
|
* const collection = new AsyncIterableCollection([
|
|
@@ -848,17 +970,20 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
848
970
|
* // { name: "Hasan", age: 25 },
|
|
849
971
|
* // { name: "Anders", age: 30 },
|
|
850
972
|
* // ]
|
|
973
|
+
* ```
|
|
851
974
|
*/
|
|
852
975
|
sort(comparator?: Comparator<TInput>): IAsyncCollection<TInput>;
|
|
853
976
|
/**
|
|
854
977
|
* The <i>reverse</i> method will reverse the order of the collection.
|
|
855
978
|
* The reversing of the collection will be applied in chunks that are the size of <i> chunkSize </i>.
|
|
856
979
|
* @example
|
|
980
|
+
* ```ts
|
|
857
981
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
858
982
|
*
|
|
859
983
|
* const collection = new AsyncIterableCollection([-1, 2, 4, 3]);
|
|
860
984
|
* await collection.reverse().toArray();
|
|
861
985
|
* // [3, 4, 2, -1]
|
|
986
|
+
* ```
|
|
862
987
|
*/
|
|
863
988
|
reverse(chunkSize?: number): IAsyncCollection<TInput>;
|
|
864
989
|
/**
|
|
@@ -869,24 +994,29 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
869
994
|
* The <i>first</i> method returns the first item in the collection that passes <i> predicateFn </i>.
|
|
870
995
|
* By default it will get the first item. If the collection is empty or no items passes <i> predicateFn </i> than null i returned.
|
|
871
996
|
* @example
|
|
997
|
+
* ```ts
|
|
872
998
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
873
999
|
*
|
|
874
1000
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
875
1001
|
* await collection.first();
|
|
876
1002
|
* // 1
|
|
1003
|
+
* ```
|
|
877
1004
|
* @example
|
|
1005
|
+
* ```ts
|
|
878
1006
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
879
1007
|
*
|
|
880
1008
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
881
1009
|
* await collection.first(item => item > 2);
|
|
882
1010
|
* // 3
|
|
1011
|
+
* ```
|
|
883
1012
|
* @example
|
|
1013
|
+
* ```ts
|
|
884
1014
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
885
1015
|
*
|
|
886
1016
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
887
1017
|
* await collection.first(item => item > 10);
|
|
888
1018
|
* // null
|
|
889
|
-
*
|
|
1019
|
+
* ```
|
|
890
1020
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
891
1021
|
* // 3
|
|
892
1022
|
*/
|
|
@@ -895,30 +1025,37 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
895
1025
|
* The <i>firstOr</i> method returns the first item in the collection that passes <i> predicateFn </i>
|
|
896
1026
|
* By default it will get the first item. If the collection is empty or no items passes <i> predicateFn </i> than <i> defaultValue </i>.
|
|
897
1027
|
* @example
|
|
1028
|
+
* ```ts
|
|
898
1029
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
899
1030
|
*
|
|
900
1031
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
901
1032
|
* await collection.firstOr(-1);
|
|
902
1033
|
* // 1
|
|
1034
|
+
* ```
|
|
903
1035
|
* @example
|
|
1036
|
+
* ```ts
|
|
904
1037
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
905
1038
|
*
|
|
906
1039
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
907
1040
|
* await collection.firstOr(-1, item => item > 2);
|
|
908
1041
|
* // 3
|
|
1042
|
+
* ```
|
|
909
1043
|
* @example
|
|
1044
|
+
* ```ts
|
|
910
1045
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
911
1046
|
*
|
|
912
1047
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
913
1048
|
* await collection.firstOr(-1, item => item > 10);
|
|
914
1049
|
* // -1
|
|
1050
|
+
* ```
|
|
915
1051
|
* @example
|
|
1052
|
+
* ```ts
|
|
916
1053
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
917
1054
|
*
|
|
918
1055
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
919
1056
|
* await collection.firstOr(() => -1, item => item > 10);
|
|
920
1057
|
* // -1
|
|
921
|
-
*
|
|
1058
|
+
* ```
|
|
922
1059
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
923
1060
|
*/
|
|
924
1061
|
firstOr<TOutput extends TInput, TExtended = TInput>(defaultValue: AsyncLazyable<TExtended>, predicateFn?: AsyncPredicate<TInput, IAsyncCollection<TInput>, TOutput>): PromiseLike<TOutput | TExtended>;
|
|
@@ -926,24 +1063,29 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
926
1063
|
* The <i>firstOrFail</i> method returns the first item in the collection that passes <i> predicateFn </i>.
|
|
927
1064
|
* By default it will get the first item. If the collection is empty or no items passes <i> predicateFn </i> than error is thrown.
|
|
928
1065
|
* @example
|
|
1066
|
+
* ```ts
|
|
929
1067
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
930
1068
|
*
|
|
931
1069
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
932
1070
|
* await collection.firstOrFail();
|
|
933
1071
|
* // 1
|
|
934
1072
|
* @example
|
|
1073
|
+
* ```
|
|
1074
|
+
* ```ts
|
|
935
1075
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
936
1076
|
*
|
|
937
1077
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
938
1078
|
* await collection.firstOrFail(item => item > 2);
|
|
939
1079
|
* // 3
|
|
940
1080
|
* @example
|
|
1081
|
+
* ```
|
|
1082
|
+
* ```ts
|
|
941
1083
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
942
1084
|
*
|
|
943
1085
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
944
1086
|
* await collection.firstOrFail(item => item > 10);
|
|
945
1087
|
* // throws an error
|
|
946
|
-
*
|
|
1088
|
+
* ```
|
|
947
1089
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
948
1090
|
* @throws {ItemNotFoundCollectionError} {@link ItemNotFoundCollectionError}
|
|
949
1091
|
*/
|
|
@@ -952,24 +1094,29 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
952
1094
|
* The <i>last</i> method returns the last item in the collection that passes <i> predicateFn </i>.
|
|
953
1095
|
* By default it will get the last item. If the collection is empty or no items passes <i> predicateFn </i> than null i returned.
|
|
954
1096
|
* @example
|
|
1097
|
+
* ```ts
|
|
955
1098
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
956
1099
|
*
|
|
957
1100
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
958
1101
|
* await collection.last();
|
|
959
1102
|
* // 4
|
|
1103
|
+
* ```
|
|
960
1104
|
* @example
|
|
1105
|
+
* ```ts
|
|
961
1106
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
962
1107
|
*
|
|
963
1108
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
964
1109
|
* await collection.last(item => item < 4);
|
|
965
1110
|
* // 3
|
|
1111
|
+
* ```
|
|
966
1112
|
* @example
|
|
1113
|
+
* ```ts
|
|
967
1114
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
968
1115
|
*
|
|
969
1116
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
970
1117
|
* await collection.last(item => item > 10);
|
|
971
1118
|
* // null
|
|
972
|
-
*
|
|
1119
|
+
* ```
|
|
973
1120
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
974
1121
|
* // 3
|
|
975
1122
|
*/
|
|
@@ -978,30 +1125,37 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
978
1125
|
* The <i>lastOr</i> method returns the last item in the collection that passes <i> predicateFn </i>.
|
|
979
1126
|
* By default it will get the last item. If the collection is empty or no items passes <i> predicateFn </i> than <i> defaultValue </i>.
|
|
980
1127
|
* @example
|
|
1128
|
+
* ```ts
|
|
981
1129
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
982
1130
|
*
|
|
983
1131
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
984
1132
|
* await collection.lastOr(-1);
|
|
985
1133
|
* // 4
|
|
1134
|
+
* ```
|
|
986
1135
|
* @example
|
|
1136
|
+
* ```ts
|
|
987
1137
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
988
1138
|
*
|
|
989
1139
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
990
1140
|
* await collection.lastOr(-1, item => item < 4);
|
|
991
1141
|
* // 3
|
|
1142
|
+
* ```
|
|
992
1143
|
* @example
|
|
1144
|
+
* ```ts
|
|
993
1145
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
994
1146
|
*
|
|
995
1147
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
996
1148
|
* await collection.lastOr(-1, item => item > 10);
|
|
997
1149
|
* // -1
|
|
1150
|
+
* ```
|
|
998
1151
|
* @example
|
|
1152
|
+
* ```ts
|
|
999
1153
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1000
1154
|
*
|
|
1001
1155
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
1002
1156
|
* await collection.lastOr(() => -1, item => item > 10);
|
|
1003
1157
|
* // -1
|
|
1004
|
-
*
|
|
1158
|
+
* ```
|
|
1005
1159
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
1006
1160
|
*/
|
|
1007
1161
|
lastOr<TOutput extends TInput, TExtended = TInput>(defaultValue: AsyncLazyable<TExtended>, predicateFn?: AsyncPredicate<TInput, IAsyncCollection<TInput>, TOutput>): PromiseLike<TOutput | TExtended>;
|
|
@@ -1009,24 +1163,29 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
1009
1163
|
* The <i>lastOrFail</i> method returns the last item in the collection that passes <i> predicateFn </i>.
|
|
1010
1164
|
* By default it will get the last item. If the collection is empty or no items passes <i> predicateFn </i> than error is thrown.
|
|
1011
1165
|
* @example
|
|
1166
|
+
* ```ts
|
|
1012
1167
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1013
1168
|
*
|
|
1014
1169
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
1015
1170
|
* await collection.lastOrFail();
|
|
1016
1171
|
* // 4
|
|
1172
|
+
* ```
|
|
1017
1173
|
* @example
|
|
1174
|
+
* ```ts
|
|
1018
1175
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1019
1176
|
*
|
|
1020
1177
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
1021
1178
|
* await collection.lastOrFail(item => item < 4);
|
|
1022
1179
|
* // 3
|
|
1180
|
+
* ```
|
|
1023
1181
|
* @example
|
|
1182
|
+
* ```ts
|
|
1024
1183
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1025
1184
|
*
|
|
1026
1185
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
1027
1186
|
* await collection.lastOrFail(item => item > 10);
|
|
1028
1187
|
* // throws an error
|
|
1029
|
-
*
|
|
1188
|
+
* ```
|
|
1030
1189
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
1031
1190
|
* @throws {ItemNotFoundCollectionError} {@link ItemNotFoundCollectionError}
|
|
1032
1191
|
*/
|
|
@@ -1035,18 +1194,21 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
1035
1194
|
* The <i>before</i> method returns the item that comes before the first item that matches <i>predicateFn</i>.
|
|
1036
1195
|
* If the <i>predicateFn</i> does not match or matches the first item then null is returned.
|
|
1037
1196
|
* @example
|
|
1197
|
+
* ```ts
|
|
1038
1198
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1039
1199
|
*
|
|
1040
1200
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
1041
1201
|
* await collection.before(item => item === 2);
|
|
1042
1202
|
* // 1
|
|
1203
|
+
* ```
|
|
1043
1204
|
* @example
|
|
1205
|
+
* ```ts
|
|
1044
1206
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1045
1207
|
*
|
|
1046
1208
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
1047
1209
|
* await collection.before(item => item === 1);
|
|
1048
1210
|
* // null
|
|
1049
|
-
*
|
|
1211
|
+
* ```
|
|
1050
1212
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
1051
1213
|
*/
|
|
1052
1214
|
before(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): PromiseLike<TInput | null>;
|
|
@@ -1054,24 +1216,29 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
1054
1216
|
* The <i>beforeOr</i> method returns the item that comes before the first item that matches <i>predicateFn</i>.
|
|
1055
1217
|
* If the collection is empty or the <i>predicateFn</i> does not match or matches the first item then <i>defaultValue</i> is returned.
|
|
1056
1218
|
* @example
|
|
1219
|
+
* ```ts
|
|
1057
1220
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1058
1221
|
*
|
|
1059
1222
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
1060
1223
|
* await collection.beforeOr(-1, item => item === 2);
|
|
1061
1224
|
* // 1
|
|
1225
|
+
* ```
|
|
1062
1226
|
* @example
|
|
1227
|
+
* ```ts
|
|
1063
1228
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1064
1229
|
*
|
|
1065
1230
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
1066
1231
|
* await collection.beforeOr(-1, item => item === 1);
|
|
1067
1232
|
* // -1
|
|
1233
|
+
* ```
|
|
1068
1234
|
* @example
|
|
1235
|
+
* ```ts
|
|
1069
1236
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1070
1237
|
*
|
|
1071
1238
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
1072
1239
|
* await collection.beforeOr(() => -1, item => item === 1);
|
|
1073
1240
|
* // -1
|
|
1074
|
-
*
|
|
1241
|
+
* ```
|
|
1075
1242
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
1076
1243
|
*/
|
|
1077
1244
|
beforeOr<TExtended = TInput>(defaultValue: AsyncLazyable<TExtended>, predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): PromiseLike<TInput | TExtended>;
|
|
@@ -1079,18 +1246,21 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
1079
1246
|
* The <i>beforeOrFail</i> method returns the item that comes before the first item that matches <i>predicateFn</i>.
|
|
1080
1247
|
* If the collection is empty or the <i>predicateFn</i> does not match or matches the first item then an error is thrown.
|
|
1081
1248
|
* @example
|
|
1249
|
+
* ```ts
|
|
1082
1250
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1083
1251
|
*
|
|
1084
1252
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
1085
1253
|
* await collection.beforeOrFail(item => item === 2);
|
|
1086
1254
|
* // 1
|
|
1255
|
+
* ```
|
|
1087
1256
|
* @example
|
|
1257
|
+
* ```ts
|
|
1088
1258
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1089
1259
|
*
|
|
1090
1260
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
1091
1261
|
* await collection.beforeOrFail(item => item === 1);
|
|
1092
1262
|
* // error is thrown
|
|
1093
|
-
*
|
|
1263
|
+
* ```
|
|
1094
1264
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
1095
1265
|
* @throws {ItemNotFoundCollectionError} {@link ItemNotFoundCollectionError}
|
|
1096
1266
|
*/
|
|
@@ -1099,18 +1269,21 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
1099
1269
|
* The <i>after</i> method returns the item that comes after the first item that matches <i>predicateFn</i>.
|
|
1100
1270
|
* If the collection is empty or the <i>predicateFn</i> does not match or matches the last item then null is returned.
|
|
1101
1271
|
* @example
|
|
1272
|
+
* ```ts
|
|
1102
1273
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1103
1274
|
*
|
|
1104
1275
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
1105
1276
|
* await collection.after(item => item === 2);
|
|
1106
1277
|
* // 3
|
|
1278
|
+
* ```
|
|
1107
1279
|
* @example
|
|
1280
|
+
* ```ts
|
|
1108
1281
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1109
1282
|
*
|
|
1110
1283
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
1111
1284
|
* await collection.after(item => item === 4);
|
|
1112
1285
|
* // null
|
|
1113
|
-
*
|
|
1286
|
+
* ```
|
|
1114
1287
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
1115
1288
|
*/
|
|
1116
1289
|
after(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): PromiseLike<TInput | null>;
|
|
@@ -1118,24 +1291,29 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
1118
1291
|
* The <i>afterOr</i> method returns the item that comes after the first item that matches <i>predicateFn</i>.
|
|
1119
1292
|
* If the collection is empty or the <i>predicateFn</i> does not match or matches the last item then <i>defaultValue</i> is returned.
|
|
1120
1293
|
* @example
|
|
1294
|
+
* ```ts
|
|
1121
1295
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1122
1296
|
*
|
|
1123
1297
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
1124
1298
|
* await collection.afterOr(-1, item => item === 2);
|
|
1125
1299
|
* // 3
|
|
1300
|
+
* ```
|
|
1126
1301
|
* @example
|
|
1302
|
+
* ```ts
|
|
1127
1303
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1128
1304
|
*
|
|
1129
1305
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
1130
1306
|
* await collection.afterOr(-1, item => item === 4);
|
|
1131
1307
|
* // -1
|
|
1132
1308
|
* @example
|
|
1309
|
+
* ```
|
|
1310
|
+
* ```ts
|
|
1133
1311
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1134
1312
|
*
|
|
1135
1313
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
1136
1314
|
* await collection.afterOr(() => -1, item => item === 4);
|
|
1137
1315
|
* // -1
|
|
1138
|
-
*
|
|
1316
|
+
* ```
|
|
1139
1317
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
1140
1318
|
*/
|
|
1141
1319
|
afterOr<TExtended = TInput>(defaultValue: AsyncLazyable<TExtended>, predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): PromiseLike<TInput | TExtended>;
|
|
@@ -1143,18 +1321,21 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
1143
1321
|
* The <i>afterOrFail</i> method returns the item that comes after the first item that matches <i>predicateFn</i>.
|
|
1144
1322
|
* If the collection is empty or the <i>predicateFn</i> does not match or matches the last item then an error is thrown.
|
|
1145
1323
|
* @example
|
|
1324
|
+
* ```ts
|
|
1146
1325
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1147
1326
|
*
|
|
1148
1327
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
1149
1328
|
* await collection.afterOrFail(item => item === 2);
|
|
1150
1329
|
* // 3
|
|
1330
|
+
* ```
|
|
1151
1331
|
* @example
|
|
1332
|
+
* ```ts
|
|
1152
1333
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1153
1334
|
*
|
|
1154
1335
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4]);
|
|
1155
1336
|
* await collection.afterOrFail(item => item === 4);
|
|
1156
1337
|
* // error is thrown
|
|
1157
|
-
*
|
|
1338
|
+
* ```
|
|
1158
1339
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
1159
1340
|
* @throws {ItemNotFoundCollectionError} {@link ItemNotFoundCollectionError}
|
|
1160
1341
|
*/
|
|
@@ -1163,24 +1344,29 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
1163
1344
|
* The <i>sole</i> method returns the first item in the collection that passes <i>predicateFn</i>, but only if <i>predicateFn</i> matches exactly one item.
|
|
1164
1345
|
* If no items matches or multiple items are found an error will be thrown.
|
|
1165
1346
|
* @example
|
|
1347
|
+
* ```ts
|
|
1166
1348
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1167
1349
|
*
|
|
1168
1350
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]);
|
|
1169
1351
|
* await collection.sole(item => item === 4);
|
|
1170
1352
|
* // 4
|
|
1353
|
+
* ```
|
|
1171
1354
|
* @example
|
|
1355
|
+
* ```ts
|
|
1172
1356
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1173
1357
|
*
|
|
1174
1358
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4, 4, 5]);
|
|
1175
1359
|
* await collection.sole(item => item === 4);
|
|
1176
1360
|
* // error is thrown
|
|
1361
|
+
* ```
|
|
1177
1362
|
* @example
|
|
1363
|
+
* ```ts
|
|
1178
1364
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1179
1365
|
*
|
|
1180
1366
|
* const collection = new AsyncIterableCollection([1, 2, 3, 5]);
|
|
1181
1367
|
* await collection.sole(item => item === 4);
|
|
1182
1368
|
* // error is thrown
|
|
1183
|
-
*
|
|
1369
|
+
* ```
|
|
1184
1370
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
1185
1371
|
* @throws {ItemNotFoundCollectionError} {@link ItemNotFoundCollectionError}
|
|
1186
1372
|
* @throws {MultipleItemsFoundCollectionError} {@link MultipleItemsFoundCollectionError}
|
|
@@ -1189,76 +1375,76 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
1189
1375
|
/**
|
|
1190
1376
|
* The <i>nth</i> method creates a new collection consisting of every n-th item.
|
|
1191
1377
|
* @example
|
|
1378
|
+
* ```ts
|
|
1192
1379
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1193
1380
|
*
|
|
1194
1381
|
* const collection = new AsyncIterableCollection(["a", "b", "c", "d", "e", "f"]).nth(4);
|
|
1195
1382
|
* await collection.toArray();
|
|
1196
1383
|
* // ["a", "e"]
|
|
1384
|
+
* ```
|
|
1197
1385
|
*/
|
|
1198
1386
|
nth(step: number): IAsyncCollection<TInput>;
|
|
1199
1387
|
/**
|
|
1200
1388
|
* The <i>count</i> method returns the total number of items in the collection that passes <i>predicateFn</i>.
|
|
1201
1389
|
* @example
|
|
1390
|
+
* ```ts
|
|
1202
1391
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1203
1392
|
*
|
|
1204
1393
|
* const collection = new AsyncIterableCollection([1, 2, 3, 4, 5, 6]);
|
|
1205
1394
|
* await collection.count(value => value % 2 === 0);
|
|
1206
1395
|
* // 3
|
|
1207
|
-
*
|
|
1396
|
+
* ```
|
|
1208
1397
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
1209
1398
|
*/
|
|
1210
1399
|
count(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): PromiseLike<number>;
|
|
1211
1400
|
/**
|
|
1212
1401
|
* The <i>size</i> returns the size of the collection.
|
|
1213
|
-
* @throws {CollectionError} {@link CollectionError}
|
|
1214
1402
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
1215
1403
|
*/
|
|
1216
1404
|
size(): PromiseLike<number>;
|
|
1217
1405
|
/**
|
|
1218
1406
|
* The <i>isEmpty</i> returns true if the collection is empty.
|
|
1219
|
-
* @throws {CollectionError} {@link CollectionError}
|
|
1220
1407
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
1221
1408
|
*/
|
|
1222
1409
|
isEmpty(): PromiseLike<boolean>;
|
|
1223
1410
|
/**
|
|
1224
1411
|
* The <i>isNotEmpty</i> returns true if the collection is not empty.
|
|
1225
|
-
* @throws {CollectionError} {@link CollectionError}
|
|
1226
1412
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
1227
1413
|
*/
|
|
1228
1414
|
isNotEmpty(): PromiseLike<boolean>;
|
|
1229
1415
|
/**
|
|
1230
1416
|
* The <i>searchFirst</i> return the index of the first item that matches <i>predicateFn</i>.
|
|
1231
1417
|
* @example
|
|
1418
|
+
* ```ts
|
|
1232
1419
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1233
1420
|
*
|
|
1234
1421
|
* const collection = new AsyncIterableCollection(["a", "b", "b", "c"]);
|
|
1235
1422
|
* await collection.searchFirst(item => item === "b");
|
|
1236
1423
|
* // 1
|
|
1237
|
-
*
|
|
1424
|
+
* ```
|
|
1238
1425
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
1239
1426
|
*/
|
|
1240
1427
|
searchFirst(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): PromiseLike<number>;
|
|
1241
1428
|
/**
|
|
1242
1429
|
* The <i>searchLast</i> return the index of the last item that matches <i>predicateFn</i>.
|
|
1243
1430
|
* @example
|
|
1431
|
+
* ```ts
|
|
1244
1432
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1245
1433
|
*
|
|
1246
1434
|
* const collection = new AsyncIterableCollection(["a", "b", "b", "c"]);
|
|
1247
1435
|
* await collection.searchLast(item => item === "b");
|
|
1248
1436
|
* // 2
|
|
1249
|
-
*
|
|
1437
|
+
* ```
|
|
1250
1438
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
1251
1439
|
*/
|
|
1252
1440
|
searchLast(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>): PromiseLike<number>;
|
|
1253
1441
|
/**
|
|
1254
1442
|
* The <i>forEach</i> method iterates through all items in the collection.
|
|
1255
|
-
* @throws {CollectionError} {@link CollectionError}
|
|
1256
1443
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
1257
1444
|
*/
|
|
1258
1445
|
forEach(callback: AsyncForEach<TInput, IAsyncCollection<TInput>>): PromiseLike<void>;
|
|
1259
1446
|
/**
|
|
1260
1447
|
* The <i>toArray</i> method converts the collection to a new array.
|
|
1261
|
-
* @throws {CollectionError} {@link CollectionError}
|
|
1262
1448
|
* @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
|
|
1263
1449
|
*/
|
|
1264
1450
|
toArray(): PromiseLike<TInput[]>;
|
|
@@ -1266,6 +1452,7 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
1266
1452
|
* The <i>delay</i> method will add delay between each iteration.
|
|
1267
1453
|
* This method is especially useful for situations where you may be interacting with external APIs that rate limit incoming requests:
|
|
1268
1454
|
* @example
|
|
1455
|
+
* ```ts
|
|
1269
1456
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1270
1457
|
*
|
|
1271
1458
|
* // An iterator that will fetch all users from a specific api
|
|
@@ -1273,11 +1460,13 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
1273
1460
|
* const apiIterator = new ApiIterator();
|
|
1274
1461
|
* const collection = new AsyncIterableCollection(apiIterator);
|
|
1275
1462
|
* await collection.delay(1000).forEach(user => console.log(user))
|
|
1463
|
+
* ```
|
|
1276
1464
|
*/
|
|
1277
1465
|
delay(time: TimeSpan): IAsyncCollection<TInput>;
|
|
1278
1466
|
/**
|
|
1279
1467
|
* The <i>abort</i> method will abort iteration of the collection by passing <i>{@link AbortSignal}</i>.
|
|
1280
1468
|
* @example
|
|
1469
|
+
* ```ts
|
|
1281
1470
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1282
1471
|
*
|
|
1283
1472
|
* // An iterator that will fetch all users from a specific api
|
|
@@ -1285,12 +1474,14 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
1285
1474
|
* const apiIterator = new ApiIterator();
|
|
1286
1475
|
* const collection = new AsyncIterableCollection(apiIterator);
|
|
1287
1476
|
* await collection.delay(1000).forEach(user => console.log(user))
|
|
1477
|
+
* ```
|
|
1288
1478
|
*/
|
|
1289
1479
|
takeUntilAbort(abortSignal: AbortSignal, shouldThrow?: boolean): IAsyncCollection<TInput>;
|
|
1290
1480
|
/**
|
|
1291
1481
|
* The <I>timeout</i> method returns a new collection that will iterate values until the specified time.
|
|
1292
1482
|
* After that time, the collection will then stop iterating:
|
|
1293
1483
|
* @example
|
|
1484
|
+
* ```ts
|
|
1294
1485
|
* import { AsyncIterableCollection } from "@daiso-tech/core";;
|
|
1295
1486
|
*
|
|
1296
1487
|
* class AsyncInfiniteIterable implements AsyncIterable<number> {
|
|
@@ -1305,6 +1496,7 @@ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
|
|
|
1305
1496
|
* await collection
|
|
1306
1497
|
* .timeout(1000)
|
|
1307
1498
|
* .forEach(nbr => console.log(nbr))
|
|
1499
|
+
* ```
|
|
1308
1500
|
*/
|
|
1309
1501
|
takeUntilTimeout(timeInMs: TimeSpan, shouldThrow?: boolean): IAsyncCollection<TInput>;
|
|
1310
1502
|
};
|