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