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