@daiso-tech/core 0.0.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.
Files changed (176) hide show
  1. package/.changeset/README.md +8 -0
  2. package/.changeset/config.json +11 -0
  3. package/.changeset/sweet-peas-beg.md +5 -0
  4. package/.eslintignore +3 -0
  5. package/.eslintrc.json +50 -0
  6. package/.gitattributes +6 -0
  7. package/.github/workflows/main.yaml +54 -0
  8. package/.github/workflows/release.yaml +31 -0
  9. package/.prettierignore +4 -0
  10. package/.prettierrc.json +4 -0
  11. package/.vscode/settings.json +46 -0
  12. package/LICENSE.md +194 -0
  13. package/docs-api/.nojekyll +1 -0
  14. package/docs-api/assets/highlight.css +92 -0
  15. package/docs-api/assets/icons.js +18 -0
  16. package/docs-api/assets/icons.svg +1 -0
  17. package/docs-api/assets/main.js +60 -0
  18. package/docs-api/assets/navigation.js +1 -0
  19. package/docs-api/assets/search.js +1 -0
  20. package/docs-api/assets/style.css +1448 -0
  21. package/docs-api/classes/AsyncIterableCollection.html +437 -0
  22. package/docs-api/classes/CollectionError.html +12 -0
  23. package/docs-api/classes/IndexOverflowError.html +12 -0
  24. package/docs-api/classes/ItemNotFoundError.html +12 -0
  25. package/docs-api/classes/IterableCollection.html +434 -0
  26. package/docs-api/classes/ListCollection.html +434 -0
  27. package/docs-api/classes/MultipleItemsFoundError.html +12 -0
  28. package/docs-api/classes/UnexpectedCollectionError.html +12 -0
  29. package/docs-api/functions/isAsyncIterable.html +1 -0
  30. package/docs-api/functions/isIterable.html +1 -0
  31. package/docs-api/functions/range.html +4 -0
  32. package/docs-api/hierarchy.html +1 -0
  33. package/docs-api/index.html +1 -0
  34. package/docs-api/modules.html +60 -0
  35. package/docs-api/types/AsyncCollapse.html +1 -0
  36. package/docs-api/types/AsyncFilter.html +1 -0
  37. package/docs-api/types/AsyncFilter_.html +1 -0
  38. package/docs-api/types/AsyncFindOrSettings.html +1 -0
  39. package/docs-api/types/AsyncFindSettings.html +1 -0
  40. package/docs-api/types/AsyncForEach.html +1 -0
  41. package/docs-api/types/AsyncForEach_.html +1 -0
  42. package/docs-api/types/AsyncGroupBySettings.html +1 -0
  43. package/docs-api/types/AsyncIterableValue.html +1 -0
  44. package/docs-api/types/AsyncLazyable.html +1 -0
  45. package/docs-api/types/AsyncLazyable_.html +1 -0
  46. package/docs-api/types/AsyncMap.html +1 -0
  47. package/docs-api/types/AsyncMap_.html +1 -0
  48. package/docs-api/types/AsyncModifier.html +1 -0
  49. package/docs-api/types/AsyncModifier_.html +1 -0
  50. package/docs-api/types/AsyncReduce.html +1 -0
  51. package/docs-api/types/AsyncReduceSettings.html +1 -0
  52. package/docs-api/types/AsyncReduce_.html +1 -0
  53. package/docs-api/types/AsyncTap.html +1 -0
  54. package/docs-api/types/AsyncTap_.html +1 -0
  55. package/docs-api/types/AsyncTransform.html +1 -0
  56. package/docs-api/types/AsyncTransform_.html +1 -0
  57. package/docs-api/types/Collapse.html +1 -0
  58. package/docs-api/types/Comparator.html +1 -0
  59. package/docs-api/types/EnsureType.html +1 -0
  60. package/docs-api/types/Filter.html +1 -0
  61. package/docs-api/types/FilterGuard.html +1 -0
  62. package/docs-api/types/Filter_.html +1 -0
  63. package/docs-api/types/FindOrSettings.html +1 -0
  64. package/docs-api/types/FindSettings.html +1 -0
  65. package/docs-api/types/ForEach.html +1 -0
  66. package/docs-api/types/GroupBySettings.html +1 -0
  67. package/docs-api/types/IAsyncCollection.html +357 -0
  68. package/docs-api/types/ICollection.html +357 -0
  69. package/docs-api/types/JoinSettings.html +1 -0
  70. package/docs-api/types/Lazyable.html +1 -0
  71. package/docs-api/types/Map.html +1 -0
  72. package/docs-api/types/Modifier.html +1 -0
  73. package/docs-api/types/PageSettings.html +1 -0
  74. package/docs-api/types/RecordItem.html +1 -0
  75. package/docs-api/types/Reduce.html +1 -0
  76. package/docs-api/types/ReduceSettings.html +1 -0
  77. package/docs-api/types/ReverseSettings.html +1 -0
  78. package/docs-api/types/SliceSettings.html +1 -0
  79. package/docs-api/types/SlidingSettings.html +1 -0
  80. package/docs-api/types/Tap.html +1 -0
  81. package/docs-api/types/Transform.html +1 -0
  82. package/docs-api/types/UpdatedItem.html +1 -0
  83. package/package.json +47 -0
  84. package/src/_module.ts +2 -0
  85. package/src/collection/_module.ts +4 -0
  86. package/src/collection/_shared.ts +45 -0
  87. package/src/collection/async-iterable-collection/_module.ts +1 -0
  88. package/src/collection/async-iterable-collection/async-iterable-collection.test.ts +3195 -0
  89. package/src/collection/async-iterable-collection/async-iterable-collection.ts +1276 -0
  90. package/src/collection/async-iterable-collection/async-iterable-helpers/_module.ts +35 -0
  91. package/src/collection/async-iterable-collection/async-iterable-helpers/async-abort-iterable.ts +25 -0
  92. package/src/collection/async-iterable-collection/async-iterable-helpers/async-chunk-iterable.ts +57 -0
  93. package/src/collection/async-iterable-collection/async-iterable-helpers/async-chunk-whilte-iterable.ts +54 -0
  94. package/src/collection/async-iterable-collection/async-iterable-helpers/async-collapse-iterable.ts +40 -0
  95. package/src/collection/async-iterable-collection/async-iterable-helpers/async-count-by-iterable.ts +58 -0
  96. package/src/collection/async-iterable-collection/async-iterable-helpers/async-cross-join-iterable.ts +69 -0
  97. package/src/collection/async-iterable-collection/async-iterable-helpers/async-delay-iterable.ts +19 -0
  98. package/src/collection/async-iterable-collection/async-iterable-helpers/async-entries-iterable.ts +28 -0
  99. package/src/collection/async-iterable-collection/async-iterable-helpers/async-filter-iterable.ts +42 -0
  100. package/src/collection/async-iterable-collection/async-iterable-helpers/async-flat-map-iterable.ts +44 -0
  101. package/src/collection/async-iterable-collection/async-iterable-helpers/async-group-by-iterable.ts +48 -0
  102. package/src/collection/async-iterable-collection/async-iterable-helpers/async-insert-after-iterable.ts +57 -0
  103. package/src/collection/async-iterable-collection/async-iterable-helpers/async-insert-before-iterable.ts +57 -0
  104. package/src/collection/async-iterable-collection/async-iterable-helpers/async-map-iterable.ts +40 -0
  105. package/src/collection/async-iterable-collection/async-iterable-helpers/async-merge-iterable.ts +35 -0
  106. package/src/collection/async-iterable-collection/async-iterable-helpers/async-pad-end-iterable.ts +41 -0
  107. package/src/collection/async-iterable-collection/async-iterable-helpers/async-pad-start-iterable.ts +41 -0
  108. package/src/collection/async-iterable-collection/async-iterable-helpers/async-partion-iterable.ts +63 -0
  109. package/src/collection/async-iterable-collection/async-iterable-helpers/async-repeat-iterable.ts +40 -0
  110. package/src/collection/async-iterable-collection/async-iterable-helpers/async-reverse-iterable.ts +35 -0
  111. package/src/collection/async-iterable-collection/async-iterable-helpers/async-shuffle-iterable.ts +23 -0
  112. package/src/collection/async-iterable-collection/async-iterable-helpers/async-skip-iterable.ts +41 -0
  113. package/src/collection/async-iterable-collection/async-iterable-helpers/async-skip-until-iterable.ts +55 -0
  114. package/src/collection/async-iterable-collection/async-iterable-helpers/async-slice-iterable.ts +33 -0
  115. package/src/collection/async-iterable-collection/async-iterable-helpers/async-sliding-iterable.ts +54 -0
  116. package/src/collection/async-iterable-collection/async-iterable-helpers/async-sort-iterable.ts +18 -0
  117. package/src/collection/async-iterable-collection/async-iterable-helpers/async-split-iterable.ts +64 -0
  118. package/src/collection/async-iterable-collection/async-iterable-helpers/async-take-iterable.ts +41 -0
  119. package/src/collection/async-iterable-collection/async-iterable-helpers/async-take-until-iterable.ts +41 -0
  120. package/src/collection/async-iterable-collection/async-iterable-helpers/async-tap-iterable.ts +34 -0
  121. package/src/collection/async-iterable-collection/async-iterable-helpers/async-timeout-iterable.ts +20 -0
  122. package/src/collection/async-iterable-collection/async-iterable-helpers/async-unique-iterable.ts +49 -0
  123. package/src/collection/async-iterable-collection/async-iterable-helpers/async-update-iterable.ts +64 -0
  124. package/src/collection/async-iterable-collection/async-iterable-helpers/async-when-iterable.ts +43 -0
  125. package/src/collection/async-iterable-collection/async-iterable-helpers/async-zip-iterable.ts +45 -0
  126. package/src/collection/iterable-collection/_module.ts +1 -0
  127. package/src/collection/iterable-collection/iterable-collection.test.ts +2379 -0
  128. package/src/collection/iterable-collection/iterable-collection.ts +1317 -0
  129. package/src/collection/iterable-collection/iterable-helpers/_module.ts +32 -0
  130. package/src/collection/iterable-collection/iterable-helpers/chunk-iterable.ts +49 -0
  131. package/src/collection/iterable-collection/iterable-helpers/chunk-whilte-iterable.ts +51 -0
  132. package/src/collection/iterable-collection/iterable-helpers/collapse-iterable.ts +35 -0
  133. package/src/collection/iterable-collection/iterable-helpers/count-by-iterable.ts +49 -0
  134. package/src/collection/iterable-collection/iterable-helpers/cross-join-iterable.ts +57 -0
  135. package/src/collection/iterable-collection/iterable-helpers/entries-iterable.ts +42 -0
  136. package/src/collection/iterable-collection/iterable-helpers/filter-iterable.ts +39 -0
  137. package/src/collection/iterable-collection/iterable-helpers/flat-map-iterable.ts +35 -0
  138. package/src/collection/iterable-collection/iterable-helpers/group-by-iterable.ts +52 -0
  139. package/src/collection/iterable-collection/iterable-helpers/insert-after-iterable.ts +43 -0
  140. package/src/collection/iterable-collection/iterable-helpers/insert-before-iterable.ts +43 -0
  141. package/src/collection/iterable-collection/iterable-helpers/map-iterable.ts +35 -0
  142. package/src/collection/iterable-collection/iterable-helpers/merge-iterable.ts +31 -0
  143. package/src/collection/iterable-collection/iterable-helpers/pad-end-iterable.ts +52 -0
  144. package/src/collection/iterable-collection/iterable-helpers/pad-start-iterable.ts +52 -0
  145. package/src/collection/iterable-collection/iterable-helpers/partion-iterable.ts +46 -0
  146. package/src/collection/iterable-collection/iterable-helpers/repeat-iterable.ts +36 -0
  147. package/src/collection/iterable-collection/iterable-helpers/reverse-iterable.ts +46 -0
  148. package/src/collection/iterable-collection/iterable-helpers/shuffle-iterable.ts +36 -0
  149. package/src/collection/iterable-collection/iterable-helpers/skip-iterable.ts +37 -0
  150. package/src/collection/iterable-collection/iterable-helpers/skip-until-iterable.ts +41 -0
  151. package/src/collection/iterable-collection/iterable-helpers/slice-iterable.ts +47 -0
  152. package/src/collection/iterable-collection/iterable-helpers/sliding-iterable.ts +49 -0
  153. package/src/collection/iterable-collection/iterable-helpers/sort-iterable.ts +29 -0
  154. package/src/collection/iterable-collection/iterable-helpers/split-iterable.ts +58 -0
  155. package/src/collection/iterable-collection/iterable-helpers/take-iterable.ts +37 -0
  156. package/src/collection/iterable-collection/iterable-helpers/take-until-iterable.ts +38 -0
  157. package/src/collection/iterable-collection/iterable-helpers/tap-iterable.ts +31 -0
  158. package/src/collection/iterable-collection/iterable-helpers/unique-iterable.ts +43 -0
  159. package/src/collection/iterable-collection/iterable-helpers/update-iterable.ts +50 -0
  160. package/src/collection/iterable-collection/iterable-helpers/when-iterable.ts +37 -0
  161. package/src/collection/iterable-collection/iterable-helpers/zip-iterable.ts +41 -0
  162. package/src/collection/list-collection/_module.ts +1 -0
  163. package/src/collection/list-collection/list-collection.test.ts +2280 -0
  164. package/src/collection/list-collection/list-collection.ts +1883 -0
  165. package/src/contracts/_module.ts +1 -0
  166. package/src/contracts/collection/_module.ts +3 -0
  167. package/src/contracts/collection/_shared.ts +346 -0
  168. package/src/contracts/collection/async-collection.contract.ts +1028 -0
  169. package/src/contracts/collection/collection.contract.ts +978 -0
  170. package/src/types.ts +2 -0
  171. package/tsconfig.base.json +31 -0
  172. package/tsconfig.cjs.json +12 -0
  173. package/tsconfig.esm.json +12 -0
  174. package/tsconfig.json +10 -0
  175. package/tsconfig.types.json +12 -0
  176. package/vite.config.ts +6 -0
@@ -0,0 +1,1028 @@
1
+ import {
2
+ type SliceSettings,
3
+ type SlidingSettings,
4
+ type AsyncFilter,
5
+ type AsyncFindOrSettings,
6
+ type AsyncFindSettings,
7
+ type AsyncForEach,
8
+ type AsyncGroupBySettings,
9
+ type AsyncLazyable,
10
+ type AsyncMap,
11
+ type AsyncModifier,
12
+ type AsyncReduceSettings,
13
+ type AsyncTap,
14
+ type AsyncTransform,
15
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
16
+ type CollectionError,
17
+ type Comparator,
18
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
19
+ type ItemNotFoundError,
20
+ type JoinSettings,
21
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
22
+ type MultipleItemsFoundError,
23
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
24
+ type IndexOverflowError,
25
+ type PageSettings,
26
+ type RecordItem,
27
+ type ReverseSettings,
28
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
29
+ type UnexpectedCollectionError,
30
+ type UpdatedItem,
31
+ } from "@/contracts/collection/_shared";
32
+ import { type EnsureType } from "@/types";
33
+
34
+ /**
35
+ * @group Collections
36
+ */
37
+ export type AsyncIterableValue<TInput> =
38
+ | Iterable<TInput>
39
+ | AsyncIterable<TInput>;
40
+ /**
41
+ * @group Collections
42
+ */
43
+ export type AsyncCollapse<TValue> = TValue extends
44
+ | Array<infer TItem>
45
+ | Iterable<infer TItem>
46
+ | IAsyncCollection<infer TItem>
47
+ ? TItem
48
+ : TValue;
49
+
50
+ /**
51
+ * IAsyncCollection is immutable and all the methods return new copies
52
+ * @throws {CollectionError}
53
+ * @throws {UnexpectedCollectionError}
54
+ * @throws {IndexOverflowError}
55
+ * @throws {ItemNotFoundError}
56
+ * @throws {MultipleItemsFoundError}
57
+ * @throws {TypeError}
58
+ * @group Collections
59
+ */
60
+ export type IAsyncCollection<TInput> = AsyncIterable<TInput> & {
61
+ iterator(): AsyncIterator<TInput, void>;
62
+
63
+ entries(
64
+ throwOnNumberLimit?: boolean,
65
+ ): IAsyncCollection<RecordItem<number, TInput>>;
66
+
67
+ keys(throwOnNumberLimit?: boolean): IAsyncCollection<number>;
68
+
69
+ values(): IAsyncCollection<TInput>;
70
+
71
+ /**
72
+ * The filter method filters the collection using the given callback, keeping only those items that pass a given truth test:
73
+ * @example
74
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4, 5, 6]);
75
+ * const filtered = collection.filter(item => 2 < item && item < 5);
76
+ * await filtered.toArray();
77
+ * // [3, 4]
78
+ */
79
+ filter<TOutput extends TInput>(
80
+ filter: AsyncFilter<TInput, IAsyncCollection<TInput>, TOutput>,
81
+ throwOnNumberLimit?: boolean,
82
+ ): IAsyncCollection<TOutput>;
83
+
84
+ /**
85
+ * The map method iterates through the collection and passes each value to the given callback.
86
+ * The mapFunction is free to modify the item and return it, thus forming a new collection of modified items:
87
+ * @example
88
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]);
89
+ * const mapped = collection.map(item => item * 2);
90
+ * await mapped.toArray();
91
+ * // [2, 4, 6, 8, 10]
92
+ */
93
+ map<TOutput>(
94
+ map: AsyncMap<TInput, IAsyncCollection<TInput>, TOutput>,
95
+ throwOnNumberLimit?: boolean,
96
+ ): IAsyncCollection<TOutput>;
97
+
98
+ reduce<TOutput = TInput>(
99
+ settings: AsyncReduceSettings<
100
+ TInput,
101
+ IAsyncCollection<TInput>,
102
+ TOutput
103
+ >,
104
+ ): Promise<TOutput>;
105
+
106
+ /**
107
+ * @throws {TypeError}
108
+ */
109
+ join(settings?: JoinSettings): Promise<string>;
110
+
111
+ /**
112
+ * The collapse method collapses a collection of arrays into a single, flat collection:
113
+ * @example
114
+ * const collection = new AsyncIterableCollection([[1, 2], [3, 4]]);
115
+ * const collapsed = collection.collapse();
116
+ * await collapsed.toArray();
117
+ * // [1, 2, 3, 4]
118
+ */
119
+ collapse(): IAsyncCollection<AsyncCollapse<TInput>>;
120
+
121
+ /**
122
+ * The flatMap method returns a new array formed by applying a given callback function to each element of the array, and then collapses the result by one level.
123
+ * It is identical to a map() followed by a collapse()
124
+ * @example
125
+ * const collection = new AsyncIterableCollection([["a", "b"], ["c", "d"]]).flatMap(item => [item.length, ...item]);
126
+ * await collection.toArray();
127
+ * // [2, "a", "b", 2, "c", "d"]
128
+ */
129
+ flatMap<TOutput>(
130
+ map: AsyncMap<
131
+ TInput,
132
+ IAsyncCollection<TInput>,
133
+ AsyncIterableValue<TOutput>
134
+ >,
135
+ throwOnNumberLimit?: boolean,
136
+ ): IAsyncCollection<TOutput>;
137
+
138
+ /**
139
+ * The update method filters the collection using the given callback, keeping only those items that pass a given truth test and thereafter updates the filtered items:
140
+ * @example
141
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]);
142
+ * const updateCollection = collection.update(item => item % 2 === 0, item => item * 2);
143
+ * await updateCollection.toArray();
144
+ * // [1, 4, 3, 8, 5]
145
+ */
146
+ update<TFilterOutput extends TInput, TMapOutput>(
147
+ filter: AsyncFilter<TInput, IAsyncCollection<TInput>, TFilterOutput>,
148
+ map: AsyncMap<TFilterOutput, IAsyncCollection<TInput>, TMapOutput>,
149
+ throwOnNumberLimit?: boolean,
150
+ ): IAsyncCollection<UpdatedItem<TInput, TFilterOutput, TMapOutput>>;
151
+
152
+ /**
153
+ * The page method returns a new collection containing the items that would be present on a given page number.
154
+ * The method accepts the page number as its first argument and the number of items to show per page as its second argument:
155
+ * @example
156
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4, 5, 6, 7, 8, 9]);
157
+ * const page = collection.page({
158
+ * page: 2,
159
+ * pageSize: 3
160
+ * });
161
+ * await page.toArray();
162
+ * // [4, 5, 6]
163
+ */
164
+ page(settings: PageSettings): IAsyncCollection<TInput>;
165
+
166
+ /**
167
+ * The sum method returns the sum of all items in the collection. If the collection contains nested arrays or objects,
168
+ * you should pass a map function that returns a number to be used in sum calculation.
169
+ * You can only pass filter to filter out the items you want:
170
+ * @example
171
+ * const collection = new AsyncIterableCollection([1, 2, 3]);
172
+ * await collection.sum();
173
+ * // 6
174
+ * @throws {CollectionError} {@link CollectionError}
175
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
176
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
177
+ * @throws {TypeError} {@link TypeError}
178
+ */
179
+ sum(throwOnNumberLimit?: boolean): Promise<EnsureType<TInput, number>>;
180
+
181
+ /**
182
+ * The average method returns the average of all items in the collection. If the collection contains nested arrays or objects,
183
+ * you should pass a map function that returns a number to be used in average calculation.
184
+ * You can only pass filter to filter out the items you want:
185
+ * @example
186
+ * const collection = new AsyncIterableCollection([1, 2, 3]);
187
+ * await collection.average();
188
+ * // 2
189
+ * @throws {CollectionError} {@link CollectionError}
190
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
191
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
192
+ * @throws {TypeError} {@link TypeError}
193
+ */
194
+ average(throwOnNumberLimit?: boolean): Promise<EnsureType<TInput, number>>;
195
+
196
+ /**
197
+ * The median method returns the median of all items in the collection. If the collection contains nested arrays or objects,
198
+ * you should pass a map function that returns a number to be used in median calculation.
199
+ * You can only pass filter to filter out the items you want:
200
+ * @example
201
+ * const collection = new AsyncIterableCollection([1, 2, 3]);
202
+ * await collection.median();
203
+ * // 2
204
+ * @throws {CollectionError} {@link CollectionError}
205
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
206
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
207
+ * @throws {TypeError} {@link TypeError}
208
+ */
209
+ median(throwOnNumberLimit?: boolean): Promise<EnsureType<TInput, number>>;
210
+
211
+ /**
212
+ * The min method returns the min of all items in the collection. If the collection contains nested arrays or objects,
213
+ * you should pass a map function that returns a number to be used in min calculation.
214
+ * You can only pass filter to filter out the items you want:
215
+ * @example
216
+ * const collection = new AsyncIterableCollection([1, 2, 3]);
217
+ * await collection.min();
218
+ * // 1
219
+ * @throws {CollectionError} {@link CollectionError}
220
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
221
+ * @throws {TypeError} {@link TypeError}
222
+ */
223
+ min(): Promise<EnsureType<TInput, number>>;
224
+
225
+ /**
226
+ * The max method returns the max of all items in the collection. If the collection contains nested arrays or objects,
227
+ * you should pass a map function that returns a number to be used in max calculation.
228
+ * You can only pass filter to filter out the items you want:
229
+ * @example
230
+ * const collection = new AsyncIterableCollection([1, 2, 3]);
231
+ * await collection.max();
232
+ * // 3
233
+ * @throws {CollectionError} {@link CollectionError}
234
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
235
+ * @throws {TypeError} {@link TypeError}
236
+ */
237
+ max(): Promise<EnsureType<TInput, number>>;
238
+
239
+ /**
240
+ * The percentage method may be used to quickly determine the percentage of items in the collection that pass a given truth test
241
+ * @example
242
+ * const collection = new AsyncIterableCollection([1, 1, 2, 2, 2, 3]);
243
+ * await collection.percentage(value => value === 1);
244
+ * // 33.333
245
+ * @throws {CollectionError} {@link CollectionError}
246
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
247
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
248
+ */
249
+ percentage(
250
+ filter: AsyncFilter<TInput, IAsyncCollection<TInput>>,
251
+ throwOnNumberLimit?: boolean,
252
+ ): Promise<number>;
253
+
254
+ /**
255
+ * The some method determines whether the collection has a given item.
256
+ * You must pass a closure to the some method to determine if an element exists in the collection matching a given truth test:
257
+ * @example
258
+ * const collection = new AsyncIterableCollection([0, 1, 2, 3, 4, 5]);
259
+ * await collection.some(item => item === 1);
260
+ * // true
261
+ * @throws {CollectionError} {@link CollectionError}
262
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
263
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
264
+ */
265
+ some<TOutput extends TInput>(
266
+ filter: AsyncFilter<TInput, IAsyncCollection<TInput>, TOutput>,
267
+ throwOnNumberLimit?: boolean,
268
+ ): Promise<boolean>;
269
+
270
+ /**
271
+ * The every method may be used to verify that all elements of a collection pass a given truth test:
272
+ * @example
273
+ * const collection = new AsyncIterableCollection([0, 1, 2, 3, 4, 5]);
274
+ * await collection.every(item => item < 6);
275
+ * // true
276
+ * @throws {CollectionError} {@link CollectionError}
277
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
278
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
279
+ */
280
+ every<TOutput extends TInput>(
281
+ filter: AsyncFilter<TInput, IAsyncCollection<TInput>, TOutput>,
282
+ throwOnNumberLimit?: boolean,
283
+ ): Promise<boolean>;
284
+
285
+ /**
286
+ * The take method returns items in the collection until the given callback returns true:
287
+ * @example
288
+ * const collection = new AsyncIterableCollection([0, 1, 2, 3, 4, 5]);
289
+ * const chunk = collection.take(3);
290
+ * await chunk.toArray();
291
+ * // [0, 1, 2]
292
+ * @example
293
+ * const collection = new AsyncIterableCollection([0, 1, 2, 3, 4, 5]);
294
+ * const chunk = collection.take(-2);
295
+ * await chunk.toArray();
296
+ * // [4, 5]
297
+ */
298
+ take(limit: number, throwOnNumberLimit?: boolean): IAsyncCollection<TInput>;
299
+
300
+ /**
301
+ * The takeUntil method returns items in the collection until the given callback returns true:
302
+ * @example
303
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4]);
304
+ * const chunk = collection.takeUntil(item => item >= 3);
305
+ * await chunk.toArray();
306
+ * // [1, 2]
307
+ */
308
+ takeUntil(
309
+ filter: AsyncFilter<TInput, IAsyncCollection<TInput>>,
310
+ throwOnNumberLimit?: boolean,
311
+ ): IAsyncCollection<TInput>;
312
+
313
+ /**
314
+ * The takeWhile method returns items in the collection until the given callback returns false:
315
+ * @example
316
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4]);
317
+ * const chunk = collection.takeWhile(item => item < 3);
318
+ * await chunk.toArray();
319
+ * // [1, 2]
320
+ */
321
+ takeWhile(
322
+ filter: AsyncFilter<TInput, IAsyncCollection<TInput>>,
323
+ throwOnNumberLimit?: boolean,
324
+ ): IAsyncCollection<TInput>;
325
+
326
+ /**
327
+ * The skip method returns a new collection, with the given number of elements removed from the beginning of the collection:
328
+ * @example
329
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]).skip(4);
330
+ * await collection.toArray();
331
+ * // [5, 6, 7, 8, 9, 10]
332
+ */
333
+ skip(
334
+ offset: number,
335
+ throwOnNumberLimit?: boolean,
336
+ ): IAsyncCollection<TInput>;
337
+
338
+ /**
339
+ * The skipUntil method skips over items from the collection until the given callback returns true
340
+ * and then returns the remaining items in the collection as a new collection instance:
341
+ * @example
342
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4]).skipUntil(item => item >= 3);
343
+ * await collection.toArray();
344
+ * // [3, 4]
345
+ */
346
+ skipUntil(
347
+ filter: AsyncFilter<TInput, IAsyncCollection<TInput>>,
348
+ throwOnNumberLimit?: boolean,
349
+ ): IAsyncCollection<TInput>;
350
+
351
+ /**
352
+ * The skipWhile method skips over items from the collection while the given callback returns false and then returns the remaining items in the collection as a new collection:
353
+ * @example
354
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4]).skipWhile(item => item <= 3);
355
+ * await collection.toArray();
356
+ * // [4]
357
+ */
358
+ skipWhile(
359
+ filter: AsyncFilter<TInput, IAsyncCollection<TInput>>,
360
+ throwOnNumberLimit?: boolean,
361
+ ): IAsyncCollection<TInput>;
362
+
363
+ /**
364
+ * The when method will execute the given callback when the first argument given to the method evaluates to true:
365
+ * @example
366
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4])
367
+ * .when(true, collection => collection.append([-3]))
368
+ * .when(false, collection => collection.append([20]));
369
+ * await collection.toArray();
370
+ * // [1, 2, 3, 4, -3]
371
+ */
372
+ when<TExtended = TInput>(
373
+ condition: boolean,
374
+ callback: AsyncModifier<
375
+ IAsyncCollection<TInput>,
376
+ IAsyncCollection<TExtended>
377
+ >,
378
+ ): IAsyncCollection<TInput | TExtended>;
379
+
380
+ /**
381
+ * The whenEmpty method will execute the given callback when the collection is empty:
382
+ * @example
383
+ * const collection = new AsyncIterableCollection([])
384
+ * .whenEmpty(collection => collection.append([-3]))
385
+ * await collection.toArray();
386
+ * // [-3]
387
+ * @example
388
+ * const collection = new AsyncIterableCollection([1])
389
+ * .whenEmpty(collection => collection.append([-3]))
390
+ * await collection.toArray();
391
+ * // [1]
392
+ */
393
+ whenEmpty<TExtended = TInput>(
394
+ callback: AsyncModifier<
395
+ IAsyncCollection<TInput>,
396
+ IAsyncCollection<TExtended>
397
+ >,
398
+ ): IAsyncCollection<TInput | TExtended>;
399
+
400
+ /**
401
+ * The whenNot method will execute the given callback when the first argument given to the method evaluates to false:
402
+ * @example
403
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4])
404
+ * .whenNot(true, collection => collection.append([-3]))
405
+ * .whenNot(false, collection => collection.append([20]));
406
+ * await collection.toArray();
407
+ * // [1, 2, 3, 4, 20]
408
+ */
409
+ whenNot<TExtended = TInput>(
410
+ condition: boolean,
411
+ callback: AsyncModifier<
412
+ IAsyncCollection<TInput>,
413
+ IAsyncCollection<TExtended>
414
+ >,
415
+ ): IAsyncCollection<TInput | TExtended>;
416
+
417
+ /**
418
+ * The whenNotEmpty method will execute the given callback when the collection is empty:
419
+ * @example
420
+ * const collection = new AsyncIterableCollection([])
421
+ * .whenNotEmpty(collection => collection.append([-3]))
422
+ * await collection.toArray();
423
+ * // []
424
+ * @example
425
+ * const collection = new AsyncIterableCollection([1])
426
+ * .whenNotEmpty(collection => collection.append([-3]))
427
+ * await collection.toArray();
428
+ * // [1, -3]
429
+ */
430
+ whenNotEmpty<TExtended = TInput>(
431
+ callback: AsyncModifier<
432
+ IAsyncCollection<TInput>,
433
+ IAsyncCollection<TExtended>
434
+ >,
435
+ ): IAsyncCollection<TInput | TExtended>;
436
+
437
+ /**
438
+ * The pipe method passes the collection to the given closure and returns the result of the executed closure:
439
+ * @example
440
+ * const collection = new AsyncIterableCollection([1, 2, 3]);
441
+ * const piped = await collection.pipe(collection => collection.sum());
442
+ * // 6
443
+ */
444
+ pipe<TOutput = TInput>(
445
+ callback: AsyncTransform<IAsyncCollection<TInput>, TOutput>,
446
+ ): Promise<TOutput>;
447
+
448
+ /**
449
+ * The tap method passes the collection to the given callback, allowing you to "tap" into the collection at a specific point
450
+ * and do something with the items while not affecting the collection itself.The collection is then returned by the tap method:
451
+ * @example
452
+ * const collection = await new AsyncIterableCollection([1, 2, 3, 4, 5, 6])
453
+ * .tap(collection => {
454
+ * collection
455
+ * .filter(value => value % 2 === 0)
456
+ * .forEach(value => console.log(value))
457
+ * })
458
+ * .toArray();
459
+ * // [1, 2, 3, 4, 5, 6]
460
+ */
461
+ tap(callback: AsyncTap<IAsyncCollection<TInput>>): IAsyncCollection<TInput>;
462
+
463
+ /**
464
+ * The chunk method breaks the collection into multiple, smaller collections of a given size:
465
+ * @example
466
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4, 5, 6, 7]);
467
+ * const chunks = collection.chunk(4);
468
+ * await chunks.toArray();
469
+ * // [[1, 2, 3, 4], [5, 6, 7]]
470
+ */
471
+ chunk(chunkSize: number): IAsyncCollection<IAsyncCollection<TInput>>;
472
+
473
+ /**
474
+ * The chunkWhile method breaks the collection into multiple, smaller collections based on the evaluation of the given callback.
475
+ * The chunk variable passed to the closure may be used to inspect the previous element:
476
+ * @example
477
+ * const collection = new AsyncIterableCollection("AABBCCCD".split(""));
478
+ * const chunks = collection.chunkWhile((value, index, chunk) => {
479
+ * return value === chunk.last();
480
+ * });
481
+ * await chunks.toArray();
482
+ * // [["A", "A"], ["B", "B"], ["C", "C", "C"], ["D"]]
483
+ */
484
+ chunkWhile(
485
+ filter: AsyncFilter<TInput, IAsyncCollection<TInput>>,
486
+ throwOnNumberLimit?: boolean,
487
+ ): IAsyncCollection<IAsyncCollection<TInput>>;
488
+
489
+ /**
490
+ * The split method breaks a collection into the given number of groups:
491
+ * @example
492
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]);
493
+ * const chunks = collection.split(3);
494
+ * await chunks.toArray();
495
+ * // [[1, 2], [3, 4], [5]]
496
+ */
497
+ split(
498
+ chunkAmount: number,
499
+ throwOnNumberLimit?: boolean,
500
+ ): IAsyncCollection<IAsyncCollection<TInput>>;
501
+
502
+ /**
503
+ * The partition method is used to separate elements that pass a given truth test from those that do not:
504
+ * @example
505
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4, 5, 6]);
506
+ * collection.partition(item => item < 3);
507
+ * await collection.toArray();
508
+ * // [[1, 2], [3, 4, 5, 6]]
509
+ */
510
+ partition(
511
+ filter: AsyncFilter<TInput, IAsyncCollection<TInput>>,
512
+ throwOnNumberLimit?: boolean,
513
+ ): IAsyncCollection<IAsyncCollection<TInput>>;
514
+
515
+ /**
516
+ * The sliding method returns a new collection of chunks representing a "sliding window" view of the items in the collection:
517
+ * @experimental
518
+ * @example
519
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]).sliding(2);
520
+ * await collection.toArray();
521
+ * // [[1, 2], [2, 3], [3, 4], [4, 5]]
522
+ */
523
+ sliding(
524
+ settings: SlidingSettings,
525
+ ): IAsyncCollection<IAsyncCollection<TInput>>;
526
+
527
+ /**
528
+ * The groupBy method groups the collection's items by a given map function:
529
+ * @example
530
+ * const collection = new AsyncIterableCollection(["a", "a", "a", "b", "b", "c"]);
531
+ * const group = await collection
532
+ * .groupBy()
533
+ * .map(async ([key, value]) => [key, await value.toArray()]).toArray();
534
+ * // [["a", ["a", "a", "a"]], ["b", ["b", "b", "b"]], ["c", ["c"]]]
535
+ * @example
536
+ * const collection = new AsyncIterableCollection(["alice@gmail.com", "bob@yahoo.com", "carlos@gmail.com"]);
537
+ * const group = await collection
538
+ * .groupBy(item => item.split("@")[1])
539
+ * .map(([key, value]) => [key, await value.toArray()]).toArray();
540
+ * // [["gmail.com", ["alice@gmail.com", "carlos@gmail.com"]], ["yahoo.com", ["bob@yahoo.com"]]]
541
+ */
542
+ groupBy<TOutput = TInput>(
543
+ settings?: AsyncGroupBySettings<
544
+ TInput,
545
+ IAsyncCollection<TInput>,
546
+ TOutput
547
+ >,
548
+ ): IAsyncCollection<RecordItem<TOutput, IAsyncCollection<TInput>>>;
549
+
550
+ /**
551
+ * The countBy method counts the occurrences of values in the collection.
552
+ * By default, the method counts the occurrences of every element, allowing you to count certain "types" of elements in the collection:
553
+ * @example
554
+ * const collection = new AsyncIterableCollection(["a", "a", "a", "b", "b", "c"]);
555
+ * const count = await collection.countBy();
556
+ * // [["a", 3], ["b", 2], ["c", 1]]
557
+ * @example
558
+ * const collection = new AsyncIterableCollection(["alice@gmail.com", "bob@yahoo.com", "carlos@gmail.com"]);
559
+ * const count = await collection.countBy(item => item.split("@")[1])
560
+ * // [["gmail.com", 2], ["yahoo.com", 1]]
561
+ */
562
+ countBy<TOutput = TInput>(
563
+ settings?: AsyncGroupBySettings<
564
+ TInput,
565
+ IAsyncCollection<TInput>,
566
+ TOutput
567
+ >,
568
+ ): IAsyncCollection<RecordItem<TOutput, number>>;
569
+
570
+ /**
571
+ * The unique method removes all duplicate values from the collection:
572
+ * @example
573
+ * const collection = new AsyncIterableCollection([1, 1, 2, 2, 3, 4, 2]);
574
+ * await collection.unique().toArray();
575
+ * // [1, 2, 3, 4]
576
+ * @example
577
+ * const collection = new AsyncIterableCollection([
578
+ * { name: "iPhone 6", brand: "Apple", type: "phone" },
579
+ * { name: "iPhone 5", brand: "Apple", type: "phone" },
580
+ * { name: "Apple Watch", brand: "Apple", type: "watch" },
581
+ * { name: "Galaxy S6", brand: "Samsung", type: "phone" },
582
+ * { name: "Galaxy Gear", brand: "Samsung", type: "watch" },
583
+ * ]);
584
+ * const unique = collection.unique(item => item.brand);
585
+ * await unique.toArray();
586
+ * // [
587
+ * { name: "iPhone 6", brand: "Apple", type: "phone" },
588
+ * { name: "Galaxy S6", brand: "Samsung", type: "phone" },
589
+ * ]
590
+ */
591
+ unique<TOutput = TInput>(
592
+ settings?: AsyncGroupBySettings<
593
+ TInput,
594
+ IAsyncCollection<TInput>,
595
+ TOutput
596
+ >,
597
+ ): IAsyncCollection<TInput>;
598
+
599
+ /**
600
+ * The diff method will return the values in the original collection that are not present in the given iterable:
601
+ * @example
602
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]);
603
+ * const difference = collection.difference([2, 4, 6, 8]);
604
+ * await difference.toArray();
605
+ * // [1, 3, 5]
606
+ */
607
+ difference<TOutput = TInput>(
608
+ iterable: AsyncIterableValue<TInput>,
609
+ map?: AsyncMap<TInput, IAsyncCollection<TInput>, TOutput>,
610
+ ): IAsyncCollection<TInput>;
611
+
612
+ /**
613
+ * The repeat method will repat the current collection given amount
614
+ * @example
615
+ * const collection = new ListCollection([1, 2, 3]);
616
+ * const newCollection = collection.repeat(3);
617
+ * newCollection.toArray();
618
+ * // [1, 2, 3, 1, 2, 3, 1, 2, 3]
619
+ */
620
+ repeat(amount: number): IAsyncCollection<TInput>;
621
+
622
+ /**
623
+ * The padStart method pads this collection with another item (multiple times, if needed) until the resulting collection reaches the given length.
624
+ * The padding is applied from the start of this collection:
625
+ * @example
626
+ * new ListCollection("abc").padStart(10, "foo").join({ seperator: "" });
627
+ * // "foofoofabc"
628
+ *
629
+ * new ListCollection("abc").padStart(6, "123465").join({ seperator: "" });
630
+ * // "123abc"
631
+ *
632
+ * new ListCollection("abc").padStart(8, "0").join({ seperator: "" });
633
+ * // "00000abc"
634
+ *
635
+ * new ListCollection("abc").padStart(1, "_").join({ seperator: "" });
636
+ * // "abc"
637
+ */
638
+ padStart<TExtended = TInput>(
639
+ maxLength: number,
640
+ fillItems: AsyncIterableValue<TExtended>,
641
+ ): IAsyncCollection<TInput | TExtended>;
642
+
643
+ /**
644
+ * The padEnd method pads this collection with another item (multiple times, if needed) until the resulting collection reaches the given length.
645
+ * The padding is applied from the end of this collection:
646
+ * @example
647
+ * new ListCollection("abc").padEnd(10, "foo").join({ seperator: "" });
648
+ * // "abcfoofoof"
649
+ *
650
+ * new ListCollection("abc").padEnd(6, "123465").join({ seperator: "" });
651
+ * // "abc123"
652
+ *
653
+ * new ListCollection("abc").padEnd(8, "0").join({ seperator: "" });
654
+ * // "abc00000"
655
+ *
656
+ * new ListCollection("abc").padEnd(1, "_").join({ seperator: "" });
657
+ * // "abc"
658
+ */
659
+ padEnd<TExtended = TInput>(
660
+ maxLength: number,
661
+ fillItems: AsyncIterableValue<TExtended>,
662
+ ): IAsyncCollection<TInput | TExtended>;
663
+
664
+ /**
665
+ * The slice is the same as Array.slice method. Se documentation on mdn:
666
+ * @link {https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice}
667
+ */
668
+ slice(settings?: SliceSettings): IAsyncCollection<TInput>;
669
+
670
+ /**
671
+ * The prepend method adds items to the beginning of the collection:
672
+ * @example
673
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]).prepend([-1, 20]);
674
+ * await collection.toArray();
675
+ * // [-1, 20, 1, 2, 3, 4, 5]
676
+ */
677
+ prepend<TExtended = TInput>(
678
+ iterable: AsyncIterableValue<TInput | TExtended>,
679
+ ): IAsyncCollection<TInput | TExtended>;
680
+
681
+ /**
682
+ * The append method adds items to the end of the collection:
683
+ * @example
684
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]).append([-1, -2]);
685
+ * await collection.toArray();
686
+ * // [1, 2, 3, 4, 5, -1, -2,]
687
+ */
688
+ append<TExtended = TInput>(
689
+ iterable: AsyncIterableValue<TInput | TExtended>,
690
+ ): IAsyncCollection<TInput | TExtended>;
691
+
692
+ /**
693
+ * The insertBefore method adds items before a specific filtered item:
694
+ * @example
695
+ * const collection = new AsyncIterableCollection([1, 2, 2, 3, 4, 5]).insertBefore(item => item === 2, [-1, 20]);
696
+ * await collection.toArray();
697
+ * // [1, -1, 20, 2, 2, 3, 4, 5]
698
+ */
699
+ insertBefore<TExtended = TInput>(
700
+ filter: AsyncFilter<TInput, IAsyncCollection<TInput>>,
701
+ iterable: AsyncIterableValue<TInput | TExtended>,
702
+ throwOnNumberLimit?: boolean,
703
+ ): IAsyncCollection<TInput | TExtended>;
704
+
705
+ /**
706
+ * The insertAfter method adds items after a specific filtered item:
707
+ * @example
708
+ * const collection = new AsyncIterableCollection([1, 2, 2, 3, 4, 5]).insertAfter(item => item === 2, [-1, 20]);
709
+ * await collection.toArray();
710
+ * // [1, 2, -1, 20, 2, 3, 4, 5]
711
+ */
712
+ insertAfter<TExtended = TInput>(
713
+ filter: AsyncFilter<TInput, IAsyncCollection<TInput>>,
714
+ iterable: AsyncIterableValue<TInput | TExtended>,
715
+ throwOnNumberLimit?: boolean,
716
+ ): IAsyncCollection<TInput | TExtended>;
717
+
718
+ /**
719
+ * The crossJoin method cross joins the collection's values among the given arrays or collections, returning a Cartesian product with all possible permutations:
720
+ * @example
721
+ * const collection = new AsyncIterableCollection([1, 2]);
722
+ * const matrix = collection.crossJoin(["a", "b"]);
723
+ * await matrix.map(collection => collection.toArray()).toArray();
724
+ * // [
725
+ * // [1, "a"],
726
+ * // [1, "b"],
727
+ * // [2, "a"],
728
+ * // [2, "b"],
729
+ * // ]
730
+ * @example
731
+ * const collection = new AsyncIterableCollection([1, 2]);
732
+ * const matrix = collection.crossJoin(["a", "b"], ["I", "II"]);
733
+ * await matrix.map(collection => collection.toArray()).toArray();
734
+ * // [
735
+ * // [1, "a", "I"],
736
+ * // [1, "a", "II"],
737
+ * // [1, "b", "I"],
738
+ * // [1, "b", "II"],
739
+ * // [2, "a", "I"],
740
+ * // [2, "a", "II"],
741
+ * // [2, "b", "I"],
742
+ * // [2, "b", "II"],
743
+ * // ]
744
+ */
745
+ crossJoin<TExtended = TInput>(
746
+ ...iterables: Array<AsyncIterableValue<TExtended>>
747
+ ): IAsyncCollection<IAsyncCollection<TInput | TExtended>>;
748
+
749
+ /**
750
+ * The zip method merges together the values of the given array with the values of the original collection at their corresponding index:
751
+ * @example
752
+ * const collection = new AsyncIterableCollection(["Chair", "Desk"]);
753
+ * const zipped = collection.zip([100, 200]);
754
+ * await zipped.toArray();
755
+ * // [["Chari", 100], ["Desk", 200]]
756
+ */
757
+ zip<TExtended>(
758
+ iterable: AsyncIterableValue<TExtended>,
759
+ ): IAsyncCollection<RecordItem<TInput, TExtended>>;
760
+
761
+ sort(compare?: Comparator<TInput>): IAsyncCollection<TInput>;
762
+
763
+ reverse(settings?: ReverseSettings): IAsyncCollection<TInput>;
764
+
765
+ shuffle(): IAsyncCollection<TInput>;
766
+
767
+ /**
768
+ * The first method returns the first element in the collection that passes a given truth test. By default it will get the first element:
769
+ * @example
770
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4]);
771
+ * await collection.first({ filter: item => item > 2 });
772
+ * @throws {CollectionError} {@link CollectionError}
773
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
774
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
775
+ * // 3
776
+ */
777
+ first<TOutput extends TInput>(
778
+ settings?: AsyncFindSettings<TInput, IAsyncCollection<TInput>, TOutput>,
779
+ ): Promise<TOutput | null>;
780
+
781
+ /**
782
+ * The firstOr method is the same as first method but will return a provided default value if not found
783
+ * @throws {CollectionError} {@link CollectionError}
784
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
785
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
786
+ */
787
+ firstOr<TOutput extends TInput, TExtended = TInput>(
788
+ settings: AsyncFindOrSettings<
789
+ TInput,
790
+ IAsyncCollection<TInput>,
791
+ TOutput,
792
+ TExtended
793
+ >,
794
+ ): Promise<TOutput | TExtended>;
795
+
796
+ /**
797
+ * The firstOrFail method is the same as first method but will throw an Error if not found
798
+ * @throws {CollectionError} {@link CollectionError}
799
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
800
+ * @throws {ItemNotFoundError} {@link ItemNotFoundError}
801
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
802
+ */
803
+ firstOrFail<TOutput extends TInput>(
804
+ settings?: AsyncFindSettings<TInput, IAsyncCollection<TInput>, TOutput>,
805
+ ): Promise<TOutput>;
806
+
807
+ /**
808
+ * The last method returns the last element in the collection that passes a given truth test. By default it will get the last element:
809
+ * @example
810
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4]);
811
+ * await collection.last({ filter: item => item > 2 });
812
+ * // 4
813
+ * @throws {CollectionError} {@link CollectionError}
814
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
815
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
816
+ */
817
+ last<TOutput extends TInput>(
818
+ settings?: AsyncFindSettings<TInput, IAsyncCollection<TInput>, TOutput>,
819
+ ): Promise<TOutput | null>;
820
+
821
+ /**
822
+ * The lastOr method is the same as last method but will return a provided default value if not found
823
+ * @throws {CollectionError} {@link CollectionError}
824
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
825
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
826
+ */
827
+ lastOr<TOutput extends TInput, TExtended = TInput>(
828
+ settings: AsyncFindOrSettings<
829
+ TInput,
830
+ IAsyncCollection<TInput>,
831
+ TOutput,
832
+ TExtended
833
+ >,
834
+ ): Promise<TOutput | TExtended>;
835
+
836
+ /**
837
+ * The lastOrFail method is the same as last method but will throw an Error if not found
838
+ * @throws {CollectionError} {@link CollectionError}
839
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
840
+ * @throws {ItemNotFoundError} {@link ItemNotFoundError}
841
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
842
+ */
843
+ lastOrFail<TOutput extends TInput>(
844
+ settings?: AsyncFindSettings<TInput, IAsyncCollection<TInput>, TOutput>,
845
+ ): Promise<TOutput>;
846
+
847
+ /**
848
+ * The before method is the opposite of the after method. It returns the item before the given item. null is returned if the given item is not found or is the first item:
849
+ * @example
850
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4]);
851
+ * await collection.before(item => item === 2);
852
+ * // 1
853
+ * @example
854
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4]);
855
+ * await collection.before(item => item === 1);
856
+ * // null
857
+ * @throws {CollectionError} {@link CollectionError}
858
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
859
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
860
+ */
861
+ before(
862
+ filter: AsyncFilter<TInput, IAsyncCollection<TInput>>,
863
+ throwOnNumberLimit?: boolean,
864
+ ): Promise<TInput | null>;
865
+
866
+ /**
867
+ * The beforeOr method is the same as before method but will return a provided default value if not found
868
+ * @throws {CollectionError} {@link CollectionError}
869
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
870
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
871
+ */
872
+ beforeOr<TExtended = TInput>(
873
+ defaultValue: AsyncLazyable<TExtended>,
874
+ filter: AsyncFilter<TInput, IAsyncCollection<TInput>>,
875
+ throwOnNumberLimit?: boolean,
876
+ ): Promise<TInput | TExtended>;
877
+
878
+ /**
879
+ * The beforeOrFail method is the same as before method but will throw an Error if not found
880
+ * @throws {CollectionError} {@link CollectionError}
881
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
882
+ * @throws {ItemNotFoundError} {@link ItemNotFoundError}
883
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
884
+ */
885
+ beforeOrFail(
886
+ filter: AsyncFilter<TInput, IAsyncCollection<TInput>>,
887
+ throwOnNumberLimit?: boolean,
888
+ ): Promise<TInput>;
889
+
890
+ /**
891
+ * The after method returns the item after the given item. null is returned if the given item is not found or is the last item:
892
+ * @example
893
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4]);
894
+ * await collection.after(item => item === 2);
895
+ * // 3
896
+ * @example
897
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4]);
898
+ * await collection.after(item => item === 4);
899
+ * // null
900
+ * @throws {CollectionError} {@link CollectionError}
901
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
902
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
903
+ */
904
+ after(
905
+ filter: AsyncFilter<TInput, IAsyncCollection<TInput>>,
906
+ throwOnNumberLimit?: boolean,
907
+ ): Promise<TInput | null>;
908
+
909
+ /**
910
+ * The afterOr method is the same as after method but will return a provided default value if not found
911
+ * @throws {CollectionError} {@link CollectionError}
912
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
913
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
914
+ */
915
+ afterOr<TExtended = TInput>(
916
+ defaultValue: AsyncLazyable<TExtended>,
917
+ filter: AsyncFilter<TInput, IAsyncCollection<TInput>>,
918
+ throwOnNumberLimit?: boolean,
919
+ ): Promise<TInput | TExtended>;
920
+
921
+ /**
922
+ * The afterOrFail method is the same as after method but will throw an Error if not found
923
+ * @throws {CollectionError} {@link CollectionError}
924
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
925
+ * @throws {ItemNotFoundError} {@link ItemNotFoundError}
926
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
927
+ */
928
+ afterOrFail(
929
+ filter: AsyncFilter<TInput, IAsyncCollection<TInput>>,
930
+ throwOnNumberLimit?: boolean,
931
+ ): Promise<TInput>;
932
+
933
+ /**
934
+ * The sole method returns the first element in the collection that passes a given truth test, but only if the truth test matches exactly one element:
935
+ * @example
936
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4, 5]);
937
+ * await collection.sole(item => item === 4);
938
+ * // 4
939
+ * @throws {CollectionError} {@link CollectionError}
940
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
941
+ * @throws {ItemNotFoundError} {@link ItemNotFoundError}
942
+ * @throws {MultipleItemsFoundError} {@link MultipleItemsFoundError}
943
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
944
+ */
945
+ sole<TOutput extends TInput>(
946
+ filter: AsyncFilter<TInput, IAsyncCollection<TInput>, TOutput>,
947
+ throwOnNumberLimit?: boolean,
948
+ ): Promise<TOutput>;
949
+
950
+ /**
951
+ * The nth method creates a new collection consisting of every n-th element:
952
+ * @example
953
+ * const collection = new AsyncIterableCollection(["a", "b", "c", "d", "e", "f"]).nth(4);
954
+ * await collection.toArray();
955
+ * // ["a", "e"]
956
+ */
957
+ nth(step: number): IAsyncCollection<TInput>;
958
+
959
+ delay(timeInMs: number): IAsyncCollection<TInput>;
960
+
961
+ abort(signal: AbortSignal): IAsyncCollection<TInput>;
962
+
963
+ timeout(timeInMs: number): IAsyncCollection<TInput>;
964
+
965
+ /**
966
+ * The count method returns the total number of items in the collection:
967
+ * @example
968
+ * const collection = new AsyncIterableCollection([1, 2, 3, 4, 5, 6]);
969
+ * await collection.count(value => value % 2 === 0);
970
+ * // 3
971
+ * @throws {CollectionError} {@link CollectionError}
972
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
973
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
974
+ */
975
+ count(
976
+ filter: AsyncFilter<TInput, IAsyncCollection<TInput>>,
977
+ throwOnNumberLimit?: boolean,
978
+ ): Promise<number>;
979
+
980
+ /**
981
+ * @throws {CollectionError} {@link CollectionError}
982
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
983
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
984
+ */
985
+ size(throwOnNumberLimit?: boolean): Promise<number>;
986
+
987
+ /**
988
+ * @throws {CollectionError} {@link CollectionError}
989
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
990
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
991
+ */
992
+ empty(): Promise<boolean>;
993
+
994
+ /**
995
+ * @throws {CollectionError} {@link CollectionError}
996
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
997
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
998
+ */
999
+ notEmpty(): Promise<boolean>;
1000
+
1001
+ /**
1002
+ * The search method searches the collection for the given value and returns its index if found. If the item is not found, -1 is returned:
1003
+ * @throws {CollectionError} {@link CollectionError}
1004
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
1005
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
1006
+ */
1007
+ search(
1008
+ filter: AsyncFilter<TInput, IAsyncCollection<TInput>>,
1009
+ throwOnNumberLimit?: boolean,
1010
+ ): Promise<number>;
1011
+
1012
+ /**
1013
+ * @throws {CollectionError} {@link CollectionError}
1014
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
1015
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
1016
+ */
1017
+ forEach(
1018
+ callback: AsyncForEach<TInput, IAsyncCollection<TInput>>,
1019
+ throwOnNumberLimit?: boolean,
1020
+ ): Promise<void>;
1021
+
1022
+ /**
1023
+ * @throws {CollectionError} {@link CollectionError}
1024
+ * @throws {UnexpectedCollectionError} {@link UnexpectedCollectionError}
1025
+ * @throws {IndexOverflowError} {@link IndexOverflowError}
1026
+ */
1027
+ toArray(): Promise<TInput[]>;
1028
+ };