@ts-fns/stdlib 0.1.0 → 0.2.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 (135) hide show
  1. package/dist/array/index.cjs +239 -37
  2. package/dist/array/index.cjs.map +1 -1
  3. package/dist/array/index.d.cts +437 -36
  4. package/dist/array/index.d.cts.map +1 -1
  5. package/dist/array/index.d.mts +437 -36
  6. package/dist/array/index.d.mts.map +1 -1
  7. package/dist/array/index.mjs +225 -22
  8. package/dist/array/index.mjs.map +1 -1
  9. package/dist/function/index.cjs +4 -2
  10. package/dist/function/index.d.cts +128 -13
  11. package/dist/function/index.d.cts.map +1 -1
  12. package/dist/function/index.d.mts +128 -13
  13. package/dist/function/index.d.mts.map +1 -1
  14. package/dist/function/index.mjs +3 -3
  15. package/dist/{function-DnI2v0p3.mjs → function-CYHPhQCQ.mjs} +84 -6
  16. package/dist/function-CYHPhQCQ.mjs.map +1 -0
  17. package/dist/{function-CB82a2GS.cjs → function-DYPifnmg.cjs} +95 -5
  18. package/dist/function-DYPifnmg.cjs.map +1 -0
  19. package/dist/{get-yrs1Kqho.cjs → get-1kqkxPFX.cjs} +20 -8
  20. package/dist/get-1kqkxPFX.cjs.map +1 -0
  21. package/dist/{get-CWL_cu6G.mjs → get-Dv6ejLZg.mjs} +21 -3
  22. package/dist/get-Dv6ejLZg.mjs.map +1 -0
  23. package/dist/guard/index.cjs +5 -12
  24. package/dist/guard/index.cjs.map +1 -1
  25. package/dist/guard/index.d.cts +18 -17
  26. package/dist/guard/index.d.cts.map +1 -1
  27. package/dist/guard/index.d.mts +18 -17
  28. package/dist/guard/index.d.mts.map +1 -1
  29. package/dist/guard/index.mjs +4 -12
  30. package/dist/guard/index.mjs.map +1 -1
  31. package/dist/index-MbdqaUt1.d.cts +54 -0
  32. package/dist/index-MbdqaUt1.d.cts.map +1 -0
  33. package/dist/index-k-paNOu4.d.mts +54 -0
  34. package/dist/index-k-paNOu4.d.mts.map +1 -0
  35. package/dist/iterator/index.cjs +72 -26
  36. package/dist/iterator/index.cjs.map +1 -1
  37. package/dist/iterator/index.d.cts +157 -5
  38. package/dist/iterator/index.d.cts.map +1 -1
  39. package/dist/iterator/index.d.mts +157 -5
  40. package/dist/iterator/index.d.mts.map +1 -1
  41. package/dist/iterator/index.mjs +66 -24
  42. package/dist/iterator/index.mjs.map +1 -1
  43. package/dist/lens/index.cjs +3 -3
  44. package/dist/lens/index.cjs.map +1 -1
  45. package/dist/lens/index.mjs +3 -3
  46. package/dist/lens/index.mjs.map +1 -1
  47. package/dist/map/index.cjs +88 -1
  48. package/dist/map/index.cjs.map +1 -1
  49. package/dist/map/index.d.cts +130 -2
  50. package/dist/map/index.d.cts.map +1 -1
  51. package/dist/map/index.d.mts +130 -2
  52. package/dist/map/index.d.mts.map +1 -1
  53. package/dist/map/index.mjs +86 -2
  54. package/dist/map/index.mjs.map +1 -1
  55. package/dist/number/index.cjs +91 -18
  56. package/dist/number/index.cjs.map +1 -1
  57. package/dist/number/index.d.cts +134 -19
  58. package/dist/number/index.d.cts.map +1 -1
  59. package/dist/number/index.d.mts +134 -19
  60. package/dist/number/index.d.mts.map +1 -1
  61. package/dist/number/index.mjs +91 -18
  62. package/dist/number/index.mjs.map +1 -1
  63. package/dist/object/index.cjs +111 -7
  64. package/dist/object/index.cjs.map +1 -1
  65. package/dist/object/index.d.cts +186 -26
  66. package/dist/object/index.d.cts.map +1 -1
  67. package/dist/object/index.d.mts +186 -26
  68. package/dist/object/index.d.mts.map +1 -1
  69. package/dist/object/index.mjs +111 -7
  70. package/dist/object/index.mjs.map +1 -1
  71. package/dist/orNull-CJNrTjhQ.cjs +45 -0
  72. package/dist/orNull-CJNrTjhQ.cjs.map +1 -0
  73. package/dist/orNull-EeXiCxD4.mjs +34 -0
  74. package/dist/orNull-EeXiCxD4.mjs.map +1 -0
  75. package/dist/order/index.cjs +22 -1
  76. package/dist/order/index.cjs.map +1 -1
  77. package/dist/order/index.d.cts +2 -2
  78. package/dist/order/index.d.mts +2 -2
  79. package/dist/order/index.mjs +22 -1
  80. package/dist/order/index.mjs.map +1 -1
  81. package/dist/{order.constants-BWSCg3C7.d.cts → order.constants-DpGY-EDp.d.cts} +4 -1
  82. package/dist/order.constants-DpGY-EDp.d.cts.map +1 -0
  83. package/dist/{order.constants-BWSCg3C7.d.mts → order.constants-DpGY-EDp.d.mts} +4 -1
  84. package/dist/order.constants-DpGY-EDp.d.mts.map +1 -0
  85. package/dist/purry-DXnhXie9.mjs +22 -0
  86. package/dist/purry-DXnhXie9.mjs.map +1 -0
  87. package/dist/purry-Dqp_F64t.cjs +27 -0
  88. package/dist/purry-Dqp_F64t.cjs.map +1 -0
  89. package/dist/set/index.cjs +59 -1
  90. package/dist/set/index.cjs.map +1 -1
  91. package/dist/set/index.d.cts +151 -2
  92. package/dist/set/index.d.cts.map +1 -1
  93. package/dist/set/index.d.mts +151 -2
  94. package/dist/set/index.d.mts.map +1 -1
  95. package/dist/set/index.mjs +59 -2
  96. package/dist/set/index.mjs.map +1 -1
  97. package/dist/string/index.cjs +289 -15
  98. package/dist/string/index.cjs.map +1 -1
  99. package/dist/string/index.d.cts +406 -1
  100. package/dist/string/index.d.cts.map +1 -1
  101. package/dist/string/index.d.mts +406 -1
  102. package/dist/string/index.d.mts.map +1 -1
  103. package/dist/string/index.mjs +271 -4
  104. package/dist/string/index.mjs.map +1 -1
  105. package/dist/tuple/index.cjs +20 -21
  106. package/dist/tuple/index.cjs.map +1 -1
  107. package/dist/tuple/index.d.cts +27 -58
  108. package/dist/tuple/index.d.cts.map +1 -1
  109. package/dist/tuple/index.d.mts +27 -58
  110. package/dist/tuple/index.d.mts.map +1 -1
  111. package/dist/tuple/index.mjs +20 -22
  112. package/dist/tuple/index.mjs.map +1 -1
  113. package/package.json +55 -127
  114. package/dist/function-CB82a2GS.cjs.map +0 -1
  115. package/dist/function-DnI2v0p3.mjs.map +0 -1
  116. package/dist/get-CWL_cu6G.mjs.map +0 -1
  117. package/dist/get-yrs1Kqho.cjs.map +0 -1
  118. package/dist/index-BJlKyBJH.d.cts +0 -18
  119. package/dist/index-BJlKyBJH.d.cts.map +0 -1
  120. package/dist/index-DGrnGMDt.d.mts +0 -18
  121. package/dist/index-DGrnGMDt.d.mts.map +0 -1
  122. package/dist/isNotNil-DrF-ohem.cjs +0 -28
  123. package/dist/isNotNil-DrF-ohem.cjs.map +0 -1
  124. package/dist/isNotNil-R5f1hC53.mjs +0 -23
  125. package/dist/isNotNil-R5f1hC53.mjs.map +0 -1
  126. package/dist/orThrow-V91Jw2lF.mjs +0 -15
  127. package/dist/orThrow-V91Jw2lF.mjs.map +0 -1
  128. package/dist/orThrow-ejzcQYAI.cjs +0 -20
  129. package/dist/orThrow-ejzcQYAI.cjs.map +0 -1
  130. package/dist/order.constants-BWSCg3C7.d.cts.map +0 -1
  131. package/dist/order.constants-BWSCg3C7.d.mts.map +0 -1
  132. package/dist/purry-B2_0DGLV.cjs +0 -28
  133. package/dist/purry-B2_0DGLV.cjs.map +0 -1
  134. package/dist/purry-BOWmqwDB.mjs +0 -23
  135. package/dist/purry-BOWmqwDB.mjs.map +0 -1
@@ -1,30 +1,52 @@
1
1
  import { r as NotFoundError, t as EmptyArrayError } from "../errors-CJsLpYo9.mjs";
2
2
  import { a as NonEmptyArray, s as ReadonlyNonEmptyArray } from "../types-D8f67ZCe.mjs";
3
- import { i as Order } from "../order.constants-BWSCg3C7.mjs";
3
+ import { i as Order } from "../order.constants-DpGY-EDp.mjs";
4
4
 
5
5
  //#region src/array/_globalAliases.d.ts
6
+ /**
7
+ * Creates an array from an iterable or array-like object.
8
+ * @function
9
+ */
6
10
  declare const from: {
7
- <T>(arrayLike: ArrayLike<T>): T[];
8
- <T, U>(arrayLike: ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[];
9
- <T>(iterable: Iterable<T> | ArrayLike<T>): T[];
10
- <T, U>(iterable: Iterable<T> | ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[];
11
- }, fromAsync: {
12
- <T>(iterableOrArrayLike: AsyncIterable<T> | Iterable<T | PromiseLike<T>> | ArrayLike<T | PromiseLike<T>>): Promise<T[]>;
13
- <T, U>(iterableOrArrayLike: AsyncIterable<T> | Iterable<T> | ArrayLike<T>, mapFn: (value: Awaited<T>, index: number) => U, thisArg?: any): Promise<Awaited<U>[]>;
14
- }, isArray: (arg: any) => arg is any[], of: <T>(...items: T[]) => T[];
15
- declare const arrayConstructor: ArrayConstructor;
11
+ <T>(arrayLike: ArrayLike<T>): T[];
12
+ <T, U>(arrayLike: ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[];
13
+ <T>(iterable: Iterable<T> | ArrayLike<T>): T[];
14
+ <T, U>(iterable: Iterable<T> | ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[];
15
+ };
16
+ /**
17
+ * Creates an array from an async iterable.
18
+ * @function
19
+ */
20
+ declare const fromAsync: {
21
+ <T>(iterableOrArrayLike: AsyncIterable<T> | Iterable<T | PromiseLike<T>> | ArrayLike<T | PromiseLike<T>>): Promise<T[]>;
22
+ <T, U>(iterableOrArrayLike: AsyncIterable<T> | Iterable<T> | ArrayLike<T>, mapFn: (value: Awaited<T>, index: number) => U, thisArg?: any): Promise<Awaited<U>[]>;
23
+ };
24
+ /**
25
+ * Checks whether a value is an array.
26
+ * @function
27
+ */
28
+ declare const isArray: (arg: any) => arg is any[];
29
+ /**
30
+ * Creates an array containing the given values.
31
+ * @function
32
+ */
33
+ declare const of: <T>(...items: T[]) => T[];
34
+ /**
35
+ * Alias of the built-in array constructor. `new Array() === new Arr.Ctor()
36
+ * @function
37
+ */
38
+ declare const Ctor: ArrayConstructor;
16
39
  //#endregion
17
40
  //#region src/array/at.d.ts
18
41
  /**
19
- * Get an element from an array by index.
20
- *
21
- * @category Array
22
- * @param arr - The array to get the element from.
23
- * @param index - The index of the element to get.
42
+ * Gets an element from an array by index, including negative indices from the end.
43
+ * Returns a range error when the array is empty or the index is out of bounds.
24
44
  *
25
45
  * @example
26
46
  * ```ts
27
47
  * at([1, 2, 3], 1); // 2
48
+ * at(-1)([1, 2, 3]); // 3
49
+ * at([1, 2, 3], 3); // RangeError
28
50
  * ```
29
51
  */
30
52
  declare function at<T>(index: number): (arr: readonly T[]) => RangeError | T;
@@ -37,8 +59,14 @@ declare function atAssert<T>(arr: readonly T[], index: number): T;
37
59
  //#endregion
38
60
  //#region src/array/chunk.d.ts
39
61
  /**
62
+ * Splits an array into consecutive groups of the given size.
63
+ * The last chunk may contain fewer elements when the length is not evenly divisible.
40
64
  *
41
- * @throws {RangeError}
65
+ * @example
66
+ * ```ts
67
+ * chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
68
+ * chunk(2)([1, 2, 3, 4, 5]); // [[1, 2], [3, 4], [5]]
69
+ * ```
42
70
  */
43
71
  declare function chunk(size: number): <T>(arr: readonly T[]) => T[][];
44
72
  declare function chunk<T>(arr: readonly T[], size: number): T[][];
@@ -49,20 +77,58 @@ declare function chunkAssert<T>(size: number): (arr: readonly T[]) => T[][];
49
77
  declare function chunkAssert<T>(arr: readonly T[], size: number): T[][];
50
78
  //#endregion
51
79
  //#region src/array/concat.d.ts
80
+ /**
81
+ * Concatenates two arrays without mutating either input.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * concat([1, 2], [3, 4]); // [1, 2, 3, 4]
86
+ * concat([3, 4])([1, 2]); // [1, 2, 3, 4]
87
+ * ```
88
+ */
52
89
  declare function concat<T>(other: readonly T[]): (arr: readonly T[]) => T;
53
90
  declare function concat<T>(arr: readonly T[], other: readonly T[]): T;
54
91
  //#endregion
55
92
  //#region src/array/drop.d.ts
93
+ /**
94
+ * Drops the first `n` elements from an array.
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * drop([1, 2, 3, 4], 2); // [3, 4]
99
+ * drop(2)([1, 2, 3, 4]); // [3, 4]
100
+ * ```
101
+ */
56
102
  declare function drop<T>(n: number): (arr: readonly T[]) => T[];
57
103
  declare function drop<T>(arr: readonly T[], n: number): T[];
58
104
  //#endregion
59
105
  //#region src/array/every.d.ts
106
+ /**
107
+ * Tests whether every element satisfies a predicate.
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * every([2, 4, 6], n => n % 2 === 0); // true
112
+ * every(n => n > 0)([1, 2, 3]); // true
113
+ * ```
114
+ */
60
115
  declare function every<T, S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S): (arr: readonly T[]) => arr is S[];
61
116
  declare function every<T>(predicate: (value: T, index: number, array: readonly T[]) => boolean): (arr: readonly T[]) => T[];
62
117
  declare function every<T, S extends T>(arr: readonly T[], predicate: (value: T, index: number, array: readonly T[]) => value is S): arr is S[];
63
118
  declare function every<T>(arr: readonly T[], predicate: (value: T, index: number, array: readonly T[]) => boolean): T[];
64
119
  //#endregion
65
120
  //#region src/array/find.d.ts
121
+ /**
122
+ * Returns the first element that satisfies a predicate.
123
+ * Returns a not-found error when no element matches.
124
+ *
125
+ * @example
126
+ * ```ts
127
+ * find([1, 2, 3], n => n > 1); // 2
128
+ * find(n => n > 1)([1, 2, 3]); // 2
129
+ * find([1, 2, 3], n => n > 10); // NotFoundError
130
+ * ```
131
+ */
66
132
  declare function find<T, S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S): (arr: readonly T[]) => NotFoundError | S;
67
133
  declare function find<T>(predicate: (value: T, index: number, array: readonly T[]) => boolean): (arr: readonly T[]) => NotFoundError | T;
68
134
  declare function find<T, S extends T>(arr: readonly T[], predicate: (value: T, index: number, array: readonly T[]) => value is S): NotFoundError | S;
@@ -76,6 +142,17 @@ declare function findAssert<T, S extends T>(arr: readonly T[], predicate: (value
76
142
  declare function findAssert<T>(arr: readonly T[], predicate: (value: T, index: number, array: readonly T[]) => boolean): T;
77
143
  //#endregion
78
144
  //#region src/array/findIndex.d.ts
145
+ /**
146
+ * Returns the index of the first element that satisfies a predicate.
147
+ * Returns a not-found error when no element matches.
148
+ *
149
+ * @example
150
+ * ```ts
151
+ * findIndex([1, 2, 3], n => n > 1); // 1
152
+ * findIndex(n => n > 1)([1, 2, 3]); // 1
153
+ * findIndex([1, 2, 3], n => n > 10); // NotFoundError
154
+ * ```
155
+ */
79
156
  declare function findIndex<T>(predicate: (value: T, index: number, array: readonly T[]) => boolean): (arr: readonly T[]) => NotFoundError | number;
80
157
  declare function findIndex<T>(arr: readonly T[], predicate: (value: T, index: number, array: readonly T[]) => boolean): NotFoundError | number;
81
158
  declare namespace findIndex {
@@ -85,6 +162,17 @@ declare function findIndexAssert<T>(predicate: (value: T, index: number, array:
85
162
  declare function findIndexAssert<T>(arr: readonly T[], predicate: (value: T, index: number, array: readonly T[]) => boolean): number;
86
163
  //#endregion
87
164
  //#region src/array/findLast.d.ts
165
+ /**
166
+ * Returns the last element that satisfies a predicate.
167
+ * Returns a not-found error when no element matches.
168
+ *
169
+ * @example
170
+ * ```ts
171
+ * findLast([1, 2, 3, 2], n => n === 2); // 2
172
+ * findLast(n => n === 2)([1, 2, 3, 2]); // 2
173
+ * findLast([1, 2, 3], n => n > 10); // NotFoundError
174
+ * ```
175
+ */
88
176
  declare function findLast<T, S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S): (arr: readonly T[]) => NotFoundError | S;
89
177
  declare function findLast<T>(predicate: (value: T, index: number, array: readonly T[]) => boolean): (arr: readonly T[]) => NotFoundError | T;
90
178
  declare function findLast<T, S extends T>(arr: readonly T[], predicate: (value: T, index: number, array: readonly T[]) => value is S): NotFoundError | S;
@@ -96,6 +184,17 @@ declare function findLastAssert<T>(predicate: (value: T, index: number, array: r
96
184
  declare function findLastAssert<T>(arr: readonly T[], predicate: (value: T, index: number, array: readonly T[]) => boolean): T;
97
185
  //#endregion
98
186
  //#region src/array/findLastIndex.d.ts
187
+ /**
188
+ * Returns the index of the last element that satisfies a predicate.
189
+ * Returns a not-found error when no element matches.
190
+ *
191
+ * @example
192
+ * ```ts
193
+ * findLastIndex([1, 2, 3, 2], n => n === 2); // 3
194
+ * findLastIndex(n => n === 2)([1, 2, 3, 2]); // 3
195
+ * findLastIndex([1, 2, 3], n => n > 10); // NotFoundError
196
+ * ```
197
+ */
99
198
  declare function findLastIndex<T>(predicate: (value: T, index: number, array: readonly T[]) => boolean): (arr: readonly T[]) => NotFoundError | number;
100
199
  declare function findLastIndex<T>(arr: readonly T[], predicate: (value: T, index: number, array: readonly T[]) => boolean): NotFoundError | number;
101
200
  declare namespace findLastIndex {
@@ -106,7 +205,14 @@ declare function findLastIndexAssert<T>(arr: readonly T[], predicate: (value: T,
106
205
  //#endregion
107
206
  //#region src/array/first.d.ts
108
207
  /**
208
+ * Returns the first element of an array.
209
+ * Returns an empty-array error when the array has no elements.
109
210
  *
211
+ * @example
212
+ * ```ts
213
+ * first([1, 2, 3]); // 1
214
+ * first([]); // EmptyArrayError
215
+ * ```
110
216
  */
111
217
  declare function first<T>(arr: ReadonlyNonEmptyArray<T>): T[];
112
218
  declare function first<T>(arr: readonly T[]): EmptyArrayError | T;
@@ -116,16 +222,40 @@ declare namespace first {
116
222
  declare function firstAssert<T>(arr: readonly T[]): T;
117
223
  //#endregion
118
224
  //#region src/array/flatMap.d.ts
225
+ /**
226
+ * Maps each element to an array and flattens the result by one level.
227
+ *
228
+ * @example
229
+ * ```ts
230
+ * flatMap([1, 2, 3], n => [n, n * 10]); // [1, 10, 2, 20, 3, 30]
231
+ * flatMap(n => [n, n * 10])([1, 2, 3]); // [1, 10, 2, 20, 3, 30]
232
+ * ```
233
+ */
119
234
  declare function flatMap<T, U>(callbackfn: (value: T, index: number, array: readonly T[]) => U | readonly U[]): (arr: T[]) => U[];
120
235
  declare function flatMap<T, U>(arr: T[], callbackfn: (value: T, index: number, array: readonly U[]) => U[]): U[];
121
236
  //#endregion
122
237
  //#region src/array/forEach.d.ts
238
+ /**
239
+ * Runs a callback for each element and returns the original array.
240
+ *
241
+ * @example
242
+ * ```ts
243
+ * forEach([1, 2, 3], n => console.log(n)); // [1, 2, 3]
244
+ * forEach(n => console.log(n))([1, 2, 3]); // [1, 2, 3]
245
+ * ```
246
+ */
123
247
  declare function forEach<T>(callbackfn: (value: T, index: number, array: readonly T[]) => void): (arr: T[]) => T[];
124
248
  declare function forEach<T>(arr: T[], callbackfn: (value: T, index: number, array: readonly T[]) => void): T[];
125
249
  //#endregion
126
250
  //#region src/array/init.d.ts
127
251
  /**
252
+ * Returns all elements except the last.
128
253
  *
254
+ * @example
255
+ * ```ts
256
+ * init([1, 2, 3]); // [1, 2]
257
+ * init([1]); // []
258
+ * ```
129
259
  */
130
260
  declare function init<T>(arr: readonly T[]): T[];
131
261
  declare namespace init {
@@ -135,8 +265,15 @@ declare function initAssert<T>(arr: readonly T[]): T[];
135
265
  //#endregion
136
266
  //#region src/array/insert.d.ts
137
267
  /**
138
- * `with` is reserved word. So this function is uses `insert`
139
- * @throws RangeError
268
+ * Inserts or replaces the element at the given index without mutating the original array.
269
+ * Named `insert` because `with` is a reserved word.
270
+ * Returns a range error when the index is invalid.
271
+ *
272
+ * @example
273
+ * ```ts
274
+ * insert([1, 2, 3], 1, 9); // [1, 9, 3]
275
+ * insert(1, 9)([1, 2, 3]); // [1, 9, 3]
276
+ * ```
140
277
  */
141
278
  declare function insert<T>(index: number, value: T): (arr: readonly T[]) => T[];
142
279
  declare function insert<T>(arr: readonly T[], index: number, value: T): T[];
@@ -147,18 +284,52 @@ declare function insertAssert<T>(index: number, value: T): (arr: readonly T[]) =
147
284
  declare function insertAssert<T>(arr: readonly T[], index: number, value: T): T[];
148
285
  //#endregion
149
286
  //#region src/array/isEmpty.d.ts
287
+ /**
288
+ * Checks whether an array contains at least one element.
289
+ *
290
+ * @example
291
+ * ```ts
292
+ * isNotEmpty([1, 2]); // true
293
+ * isNotEmpty([]); // false
294
+ * ```
295
+ */
150
296
  declare function isNotEmpty<T>(value: T[]): value is NonEmptyArray<T>;
151
297
  declare function isNotEmpty<T>(value: readonly T[]): value is ReadonlyNonEmptyArray<T>;
298
+ /**
299
+ * Checks whether an array has no elements.
300
+ *
301
+ * @example
302
+ * ```ts
303
+ * isEmpty([]); // true
304
+ * isEmpty([1]); // false
305
+ * ```
306
+ */
152
307
  declare function isEmpty<T>(value: T[]): value is [];
153
308
  declare function isEmpty<T>(value: readonly T[]): value is readonly [];
154
309
  //#endregion
155
310
  //#region src/array/join.d.ts
311
+ /**
312
+ * Joins string array elements with a separator.
313
+ *
314
+ * @example
315
+ * ```ts
316
+ * join(['a', 'b', 'c'], '-'); // 'a-b-c'
317
+ * join('-')(['a', 'b', 'c']); // 'a-b-c'
318
+ * ```
319
+ */
156
320
  declare function join(separator: string): (arr: string[]) => string;
157
321
  declare function join(arr: string[], separator: string): string;
158
322
  //#endregion
159
323
  //#region src/array/last.d.ts
160
324
  /**
325
+ * Returns the last element of an array.
326
+ * Returns an empty-array error when the array has no elements.
161
327
  *
328
+ * @example
329
+ * ```ts
330
+ * last([1, 2, 3]); // 3
331
+ * last([]); // EmptyArrayError
332
+ * ```
162
333
  */
163
334
  declare function last<T>(arr: ReadonlyNonEmptyArray<T>): T;
164
335
  declare function last<T>(arr: readonly T[]): EmptyArrayError | T;
@@ -169,25 +340,52 @@ declare function lastAssert<T>(arr: readonly T[]): T;
169
340
  //#endregion
170
341
  //#region src/array/length.d.ts
171
342
  /**
172
- * Returns length of array
173
- * @param arr
174
- * @returns
343
+ * Returns the number of elements in an array.
344
+ *
345
+ * @example
346
+ * ```ts
347
+ * length([1, 2, 3]); // 3
348
+ * length([]); // 0
349
+ * ```
175
350
  */
176
351
  declare function length(arr: readonly unknown[]): number;
177
352
  //#endregion
178
353
  //#region src/array/map.d.ts
179
- declare function map<T, U>(callbackfn: (value: T, index: number, array: readonly T[]) => U): (arr: T[]) => U[];
180
- declare function map<T, U>(data: T[], callbackfn: (value: T, index: number, array: readonly T[]) => U): U[];
354
+ /**
355
+ * Transforms each element with a callback.
356
+ *
357
+ * @example
358
+ * ```ts
359
+ * map([1, 2, 3], n => n * 2); // [2, 4, 6]
360
+ * map(n => n * 2)([1, 2, 3]); // [2, 4, 6]
361
+ * ```
362
+ */
363
+ declare function map<T, U>(callbackfn: (value: T, index: number, array: readonly T[]) => U): (arr: readonly T[]) => U[];
364
+ declare function map<T, U>(data: readonly T[], callbackfn: (value: T, index: number, array: readonly T[]) => U): U[];
181
365
  //#endregion
182
366
  //#region src/array/ofLength.d.ts
183
367
  /**
184
- * Arr.ofLength
368
+ * Creates a sparse array with the given length.
185
369
  *
186
- * @throws {RangeError}
370
+ * @example
371
+ * ```ts
372
+ * ofLength(3); // [empty × 3]
373
+ * ofLength<string>(2); // [empty × 2]
374
+ * ```
187
375
  */
188
376
  declare function ofLength<T = unknown>(arrayLength: number): T[];
189
377
  //#endregion
190
378
  //#region src/array/partition.d.ts
379
+ /**
380
+ * Splits an array into two groups based on a predicate.
381
+ * The first group contains matching elements; the second contains the rest.
382
+ *
383
+ * @example
384
+ * ```ts
385
+ * partition([1, 2, 3, 4], n => n % 2 === 0); // [[2, 4], [1, 3]]
386
+ * partition(n => n % 2 === 0)([1, 2, 3, 4]); // [[2, 4], [1, 3]]
387
+ * ```
388
+ */
191
389
  declare function partition<T, S extends T>(predicate: (value: T, index: number, arr: readonly T[]) => value is S): (data: readonly T[]) => [S[], T[]];
192
390
  declare function partition<T>(predicate: (value: T, index: number, arr: readonly T[]) => boolean): (data: readonly T[]) => [T[], T[]];
193
391
  declare function partition<T, S extends T>(data: readonly T[], predicate: (value: T, index: number, arr: readonly T[]) => value is S): [S[], T[]];
@@ -195,7 +393,14 @@ declare function partition<T>(data: readonly T[], predicate: (value: T, index: n
195
393
  //#endregion
196
394
  //#region src/array/pop.d.ts
197
395
  /**
198
- * Array.pop
396
+ * Removes and returns the last element along with the remaining array.
397
+ * Returns an empty-array error when the array has no elements.
398
+ *
399
+ * @example
400
+ * ```ts
401
+ * pop([1, 2, 3]); // [3, [1, 2]]
402
+ * pop([]); // EmptyArrayError
403
+ * ```
199
404
  */
200
405
  declare function pop<T>(arr: ReadonlyNonEmptyArray<T>): [T, T[]];
201
406
  declare function pop<T>(arr: readonly T[]): EmptyArrayError | [T, T[]];
@@ -205,48 +410,130 @@ declare namespace pop {
205
410
  declare function popAssert<T>(arr: readonly T[]): [T, T[]];
206
411
  //#endregion
207
412
  //#region src/array/prepend.d.ts
413
+ /**
414
+ * Prepends the elements of one array to another without mutating either input.
415
+ *
416
+ * @example
417
+ * ```ts
418
+ * prepend([3, 4], [1, 2]); // [1, 2, 3, 4]
419
+ * prepend([1, 2])([3, 4]); // [1, 2, 3, 4]
420
+ * ```
421
+ */
208
422
  declare function prepend<T>(other: readonly T[]): (arr: readonly T[]) => T[];
209
423
  declare function prepend<T>(arr: readonly T[], other: readonly T[]): T[];
210
424
  //#endregion
211
425
  //#region src/array/push.d.ts
426
+ /**
427
+ * Appends a value to an array without mutating the original.
428
+ *
429
+ * @example
430
+ * ```ts
431
+ * push([1, 2], 3); // [1, 2, 3]
432
+ * push(3)([1, 2]); // [1, 2, 3]
433
+ * ```
434
+ */
212
435
  declare function push<T>(value: T): (arr: readonly T[]) => T[];
213
436
  declare function push<T>(arr: readonly T[], value: T): T[];
214
437
  //#endregion
215
438
  //#region src/array/reduce.d.ts
439
+ /**
440
+ * Reduces an array to a single value using an initial accumulator.
441
+ *
442
+ * @example
443
+ * ```ts
444
+ * reduce([1, 2, 3], (acc, n) => acc + n, 0); // 6
445
+ * reduce((acc, n) => acc + n, 0)([1, 2, 3]); // 6
446
+ * ```
447
+ */
216
448
  declare function reduce<T, U>(arr: readonly T[], callbackFn: (acc: U, value: T, index: number, array: readonly T[]) => U, initialValue: U): U;
217
449
  declare function reduce<T, U>(callbackFn: (acc: U, value: T, index: number, array: readonly T[]) => U, initialValue: U): (arr: readonly T[]) => U;
218
450
  //#endregion
219
451
  //#region src/array/reduce1.d.ts
452
+ /**
453
+ * Reduces a non-empty array to a single value using the first element as the initial accumulator.
454
+ *
455
+ * @example
456
+ * ```ts
457
+ * reduce1([1, 2, 3], (acc, n) => acc + n); // 6
458
+ * reduce1((acc, n) => acc + n)([1, 2, 3]); // 6
459
+ * ```
460
+ */
220
461
  declare function reduce1<T>(arr: readonly T[], callbackFn: (acc: T, value: T, index: number, array: readonly T[]) => T): T;
221
462
  declare function reduce1<T>(callbackFn: (acc: T, value: T, index: number, array: readonly T[]) => T): (arr: readonly T[]) => T;
222
463
  //#endregion
223
464
  //#region src/array/reduceRight.d.ts
465
+ /**
466
+ * Reduces an array from the right using an initial accumulator.
467
+ *
468
+ * @example
469
+ * ```ts
470
+ * reduceRight([1, 2, 3], (acc, n) => acc - n, 0); // -6
471
+ * reduceRight((acc, n) => acc - n, 0)([1, 2, 3]); // -6
472
+ * ```
473
+ */
224
474
  declare function reduceRight<T, U>(arr: readonly T[], callbackFn: (acc: U, value: T, index: number, array: readonly T[]) => U, initialValue: U): U;
225
475
  declare function reduceRight<T, U>(callbackFn: (acc: U, value: T, index: number, array: readonly T[]) => U, initialValue: U): (arr: readonly T[]) => U;
226
476
  //#endregion
227
477
  //#region src/array/reduceRight1.d.ts
478
+ /**
479
+ * Reduces a non-empty array from the right using the last element as the initial accumulator.
480
+ *
481
+ * @example
482
+ * ```ts
483
+ * reduceRight1([1, 2, 3], (acc, n) => acc - n); // 0
484
+ * reduceRight1((acc, n) => acc - n)([1, 2, 3]); // 0
485
+ * ```
486
+ */
228
487
  declare function reduceRight1<T>(arr: readonly T[], callbackFn: (acc: T, value: T, index: number, array: readonly T[]) => T): T;
229
488
  declare function reduceRight1<T>(callbackFn: (acc: T, value: T, index: number, array: readonly T[]) => T): (arr: readonly T[]) => T;
230
489
  //#endregion
231
490
  //#region src/array/rest.d.ts
232
491
  /**
233
- * Returns an array excluding the first entry
234
- * @param arr
235
- * @returns
492
+ * Returns all elements except the first.
493
+ *
494
+ * @example
495
+ * ```ts
496
+ * rest([1, 2, 3]); // [2, 3]
497
+ * rest([1]); // []
498
+ * ```
236
499
  */
237
500
  declare function rest<T>(arr: readonly T[]): T[];
238
501
  //#endregion
239
502
  //#region src/array/reverse.d.ts
240
- declare function reverse(index: number): <T>(arr: readonly T[]) => T[];
241
- declare function reverse<T>(arr: readonly T[], index: number): T[];
503
+ /**
504
+ * Returns a reversed copy of an array without mutating the original.
505
+ *
506
+ * @example
507
+ * ```ts
508
+ * reverse([1, 2, 3]); // [3, 2, 1]
509
+ * ```
510
+ */
511
+ declare function reverse<T>(arr: readonly T[]): T[];
242
512
  //#endregion
243
513
  //#region src/array/scan.d.ts
514
+ /**
515
+ * Returns the intermediate accumulator values produced while reducing an array.
516
+ * The first element is the initial value; each subsequent element is the accumulator after processing one more item.
517
+ *
518
+ * @example
519
+ * ```ts
520
+ * scan([1, 2, 3], (acc, n) => acc + n, 0); // [0, 1, 3, 6]
521
+ * scan((acc, n) => acc + n, 0)([1, 2, 3]); // [0, 1, 3, 6]
522
+ * ```
523
+ */
244
524
  declare function scan<T, U>(callbackFn: (acc: U, value: T, index: number, array: readonly T[]) => U, initialValue: U): (arr: T[]) => U[];
245
525
  declare function scan<T, U>(arr: T[], callbackFn: (acc: U, value: T, index: number, array: readonly T[]) => U, initialValue: U): U[];
246
526
  //#endregion
247
527
  //#region src/array/shift.d.ts
248
528
  /**
529
+ * Removes and returns the first element along with the remaining array.
530
+ * Returns an empty-array error when the array has no elements.
249
531
  *
532
+ * @example
533
+ * ```ts
534
+ * shift([1, 2, 3]); // [1, [2, 3]]
535
+ * shift([]); // EmptyArrayError
536
+ * ```
250
537
  */
251
538
  declare function shift<T>(arr: ReadonlyNonEmptyArray<T>): [T, T[]];
252
539
  declare namespace shift {
@@ -255,51 +542,141 @@ declare namespace shift {
255
542
  declare function shiftAssert<T>(arr: readonly T[]): [T, T[]];
256
543
  //#endregion
257
544
  //#region src/array/shuffle.d.ts
258
- declare function shuffle<T>(arr: T[]): T[];
545
+ /**
546
+ * Returns a shuffled copy of an array using the Fisher-Yates algorithm.
547
+ *
548
+ * @example
549
+ * ```ts
550
+ * shuffle([1, 2, 3, 4]); // e.g. [3, 1, 4, 2]
551
+ * ```
552
+ */
553
+ declare function shuffle<T>(arr: readonly T[]): T[];
259
554
  //#endregion
260
555
  //#region src/array/some.d.ts
556
+ /**
557
+ * Tests whether at least one element satisfies a predicate.
558
+ *
559
+ * @example
560
+ * ```ts
561
+ * some([1, 2, 3], n => n > 2); // true
562
+ * some(n => n > 2)([1, 2, 3]); // true
563
+ * ```
564
+ */
261
565
  declare function some<T>(predicate: (value: T, index: number, array: readonly T[]) => boolean): (arr: readonly T[]) => T[];
262
566
  declare function some<T>(arr: readonly T[], predicate: (value: T, index: number, array: readonly T[]) => boolean): T[];
263
567
  //#endregion
264
568
  //#region src/array/sort.d.ts
569
+ /**
570
+ * Returns a sorted copy of an array using a comparison function.
571
+ *
572
+ * @example
573
+ * ```ts
574
+ * sort([3, 1, 2], (a, b) => a - b); // [1, 2, 3]
575
+ * sort((a, b) => a - b)([3, 1, 2]); // [1, 2, 3]
576
+ * ```
577
+ */
265
578
  declare function sort<T>(compareFn: (left: T, right: T) => Order): (arr: T[]) => T[];
266
579
  declare function sort<T>(arr: T[], compareFn: (left: T, right: T) => Order): T[];
267
580
  //#endregion
268
581
  //#region src/array/sortBy.d.ts
582
+ /**
583
+ * Returns a sorted copy of an array by mapping each element to a comparable value first.
584
+ *
585
+ * @example
586
+ * ```ts
587
+ * sortBy([{ n: 3 }, { n: 1 }], x => x.n); // [{ n: 1 }, { n: 3 }]
588
+ * sortBy(x => x.n)([{ n: 3 }, { n: 1 }]); // [{ n: 1 }, { n: 3 }]
589
+ * ```
590
+ */
269
591
  declare function sortBy<T>(mapFn: (value: T) => Date | boolean | number | string): (arr: T[]) => T[];
270
592
  declare function sortBy<T>(arr: T[], mapFn: (value: T) => Date | boolean | number | string): T[];
271
593
  //#endregion
272
594
  //#region src/array/take.d.ts
273
595
  /**
596
+ * Returns the first `limit` elements from an array.
274
597
  *
275
- * @throws {RangeError}
598
+ * @example
599
+ * ```ts
600
+ * take([1, 2, 3, 4], 2); // [1, 2]
601
+ * take(3)([1, 2, 3, 4]); // [1, 2, 3]
602
+ * ```
276
603
  */
277
604
  declare function take<T>(limit: number): (arr: readonly T[]) => T[];
278
605
  declare function take<T>(arr: readonly T[], limit: number): T[];
279
606
  //#endregion
280
607
  //#region src/array/transpose.d.ts
608
+ /**
609
+ * Transposes a matrix so rows become columns and columns become rows.
610
+ *
611
+ * @example
612
+ * ```ts
613
+ * transpose([[1, 2], [3, 4], [5, 6]]); // [[1, 3, 5], [2, 4, 6]]
614
+ * ```
615
+ */
281
616
  declare function transpose<T>(arr: T[][]): T[][];
282
617
  //#endregion
283
618
  //#region src/array/unique.d.ts
619
+ /**
620
+ * Returns a copy of an array with duplicate values removed.
621
+ *
622
+ * @example
623
+ * ```ts
624
+ * unique([1, 2, 2, 3]); // [1, 2, 3]
625
+ * unique([]); // []
626
+ * ```
627
+ */
284
628
  declare function unique<T>(arr: readonly T[]): T[];
285
629
  //#endregion
286
630
  //#region src/array/uniqueBy.d.ts
631
+ /**
632
+ * Returns a copy of an array with duplicates removed by a derived key.
633
+ * Keeps the first occurrence for each key.
634
+ *
635
+ * @example
636
+ * ```ts
637
+ * uniqueBy([{ id: 1 }, { id: 2 }, { id: 1 }], x => x.id); // [{ id: 1 }, { id: 2 }]
638
+ * uniqueBy(x => x.id)([{ id: 1 }, { id: 2 }, { id: 1 }]); // [{ id: 1 }, { id: 2 }]
639
+ * ```
640
+ */
287
641
  declare function uniqueBy<T>(mapFn: (value: T) => unknown): (arr: T[]) => T[];
288
642
  declare function uniqueBy<T>(arr: T[], mapFn: (value: T) => unknown): T[];
289
643
  //#endregion
290
644
  //#region src/array/uniqueWith.d.ts
645
+ /**
646
+ * Returns a copy of an array with duplicates removed using a custom equality function.
647
+ * Keeps the first occurrence of each equivalent value.
648
+ *
649
+ * @example
650
+ * ```ts
651
+ * uniqueWith([1, 1.0, 2], (a, b) => a === b); // [1, 2]
652
+ * uniqueWith([], (a, b) => a === b); // []
653
+ * ```
654
+ */
291
655
  declare function uniqueWith<T>(arr: readonly T[], isEqual: (left: T, right: T) => boolean): T[];
292
656
  //#endregion
293
657
  //#region src/array/unshift.d.ts
294
658
  /**
295
- * Immutably inserts new elements at the start of an array. Returns the new array.
659
+ * Prepends a value to an array without mutating the original.
660
+ *
661
+ * @example
662
+ * ```ts
663
+ * unshift([1, 2], 0); // [0, 1, 2]
664
+ * unshift(0)([1, 2]); // [0, 1, 2]
665
+ * ```
296
666
  */
297
667
  declare function unshift<T>(value: T): (arr: readonly T[]) => T[];
298
668
  declare function unshift<T>(arr: readonly T[], value: T): T[];
299
669
  //#endregion
300
670
  //#region src/array/update.d.ts
301
671
  /**
672
+ * Replaces the element at the given index using a callback without mutating the original array.
673
+ * Returns a range error when the index is out of bounds.
302
674
  *
675
+ * @example
676
+ * ```ts
677
+ * update([1, 2, 3], 1, n => n * 10); // [1, 20, 3]
678
+ * update(1, n => n * 10)([1, 2, 3]); // [1, 20, 3]
679
+ * ```
303
680
  */
304
681
  declare function update<T>(index: number, fn: (value: T) => T): (arr: readonly T[]) => RangeError | T[];
305
682
  declare function update<T>(arr: readonly T[], index: number, fn: (value: T) => T): RangeError | T[];
@@ -311,8 +688,14 @@ declare function updateAssert<T>(arr: readonly T[], index: number, fn: (value: T
311
688
  //#endregion
312
689
  //#region src/array/window.d.ts
313
690
  /**
691
+ * Creates a sliding window of consecutive elements with the given size.
692
+ * Returns an empty array when the window size is larger than the input.
314
693
  *
315
- * @throws {RangeError}
694
+ * @example
695
+ * ```ts
696
+ * window([1, 2, 3, 4], 2); // [[1, 2], [2, 3], [3, 4]]
697
+ * window(3)([1, 2, 3, 4]); // [[1, 2, 3], [2, 3, 4]]
698
+ * ```
316
699
  */
317
700
  declare function window(size: number): <T>(arr: readonly T[]) => T[][];
318
701
  declare function window<T>(arr: readonly T[], size: number): T[][];
@@ -323,12 +706,30 @@ declare function windowAssert<T>(size: number): (arr: readonly T[]) => T[][];
323
706
  declare function windowAssert<T>(arr: readonly T[], size: number): T[][];
324
707
  //#endregion
325
708
  //#region src/array/zip.d.ts
709
+ /**
710
+ * Pairs elements from two arrays up to the length of the shorter one.
711
+ *
712
+ * @example
713
+ * ```ts
714
+ * zip([1, 2, 3], ['a', 'b']); // [[1, 'a'], [2, 'b']]
715
+ * zip(['a', 'b'])([1, 2, 3]); // [[1, 'a'], [2, 'b']]
716
+ * ```
717
+ */
326
718
  declare function zip<L, R>(other: readonly R[]): (arr: readonly L[]) => [L, R][];
327
719
  declare function zip<L, R>(arr: readonly L[], other: readonly R[]): [L, R][];
328
720
  //#endregion
329
721
  //#region src/array/zipWith.d.ts
722
+ /**
723
+ * Combines two arrays element-wise using a callback, up to the length of the shorter one.
724
+ *
725
+ * @example
726
+ * ```ts
727
+ * zipWith([1, 2, 3], [10, 20], (a, b) => a + b); // [11, 22]
728
+ * zipWith([10, 20], (a, b) => a + b)([1, 2, 3]); // [11, 22]
729
+ * ```
730
+ */
330
731
  declare function zipWith<L, R, U>(other: readonly R[], fn: (l: L, R: R) => U): (arr: readonly L[]) => U[];
331
732
  declare function zipWith<L, R, U>(arr: readonly L[], other: readonly R[], fn: (l: L, R: R) => U): U[];
332
733
  //#endregion
333
- export { arrayConstructor as Array, at, atAssert, chunk, concat, drop, every, find, findIndex, findLast, findLastIndex, first, flatMap, forEach, from, fromAsync, init, insert, isArray, isEmpty, isNotEmpty, join, last, length, map, of, ofLength, partition, pop, prepend, push, reduce, reduce1, reduceRight, reduceRight1, rest, reverse, scan, shift, shuffle, some, sort, sortBy, take, transpose, unique, uniqueBy, uniqueWith, unshift, update, window, zip, zipWith };
734
+ export { Ctor, at, chunk, concat, drop, every, find, findIndex, findLast, findLastIndex, first, flatMap, forEach, from, fromAsync, init, insert, isArray, isEmpty, isNotEmpty, join, last, length, map, of, ofLength, partition, pop, prepend, push, reduce, reduce1, reduceRight, reduceRight1, rest, reverse, scan, shift, shuffle, some, sort, sortBy, take, transpose, unique, uniqueBy, uniqueWith, unshift, update, window, zip, zipWith };
334
735
  //# sourceMappingURL=index.d.mts.map