@ts-fns/stdlib 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +132 -0
  3. package/dist/array/index.cjs +551 -0
  4. package/dist/array/index.cjs.map +1 -0
  5. package/dist/array/index.d.cts +334 -0
  6. package/dist/array/index.d.cts.map +1 -0
  7. package/dist/array/index.d.mts +334 -0
  8. package/dist/array/index.d.mts.map +1 -0
  9. package/dist/array/index.mjs +498 -0
  10. package/dist/array/index.mjs.map +1 -0
  11. package/dist/errors-CJsLpYo9.d.cts +25 -0
  12. package/dist/errors-CJsLpYo9.d.cts.map +1 -0
  13. package/dist/errors-CJsLpYo9.d.mts +25 -0
  14. package/dist/errors-CJsLpYo9.d.mts.map +1 -0
  15. package/dist/errors-Dw1kitu_.mjs +39 -0
  16. package/dist/errors-Dw1kitu_.mjs.map +1 -0
  17. package/dist/errors-O-d_Vemi.cjs +74 -0
  18. package/dist/errors-O-d_Vemi.cjs.map +1 -0
  19. package/dist/function/index.cjs +15 -0
  20. package/dist/function/index.d.cts +107 -0
  21. package/dist/function/index.d.cts.map +1 -0
  22. package/dist/function/index.d.mts +107 -0
  23. package/dist/function/index.d.mts.map +1 -0
  24. package/dist/function/index.mjs +3 -0
  25. package/dist/function-CB82a2GS.cjs +186 -0
  26. package/dist/function-CB82a2GS.cjs.map +1 -0
  27. package/dist/function-DnI2v0p3.mjs +121 -0
  28. package/dist/function-DnI2v0p3.mjs.map +1 -0
  29. package/dist/get-CWL_cu6G.mjs +27 -0
  30. package/dist/get-CWL_cu6G.mjs.map +1 -0
  31. package/dist/get-yrs1Kqho.cjs +38 -0
  32. package/dist/get-yrs1Kqho.cjs.map +1 -0
  33. package/dist/guard/index.cjs +43 -0
  34. package/dist/guard/index.cjs.map +1 -0
  35. package/dist/guard/index.d.cts +52 -0
  36. package/dist/guard/index.d.cts.map +1 -0
  37. package/dist/guard/index.d.mts +52 -0
  38. package/dist/guard/index.d.mts.map +1 -0
  39. package/dist/guard/index.mjs +40 -0
  40. package/dist/guard/index.mjs.map +1 -0
  41. package/dist/index-BJlKyBJH.d.cts +18 -0
  42. package/dist/index-BJlKyBJH.d.cts.map +1 -0
  43. package/dist/index-DGrnGMDt.d.mts +18 -0
  44. package/dist/index-DGrnGMDt.d.mts.map +1 -0
  45. package/dist/isNotNil-DrF-ohem.cjs +28 -0
  46. package/dist/isNotNil-DrF-ohem.cjs.map +1 -0
  47. package/dist/isNotNil-R5f1hC53.mjs +23 -0
  48. package/dist/isNotNil-R5f1hC53.mjs.map +1 -0
  49. package/dist/iterator/index.cjs +160 -0
  50. package/dist/iterator/index.cjs.map +1 -0
  51. package/dist/iterator/index.d.cts +71 -0
  52. package/dist/iterator/index.d.cts.map +1 -0
  53. package/dist/iterator/index.d.mts +71 -0
  54. package/dist/iterator/index.d.mts.map +1 -0
  55. package/dist/iterator/index.mjs +148 -0
  56. package/dist/iterator/index.mjs.map +1 -0
  57. package/dist/lens/index.cjs +199 -0
  58. package/dist/lens/index.cjs.map +1 -0
  59. package/dist/lens/index.d.cts +109 -0
  60. package/dist/lens/index.d.cts.map +1 -0
  61. package/dist/lens/index.d.mts +109 -0
  62. package/dist/lens/index.d.mts.map +1 -0
  63. package/dist/lens/index.mjs +187 -0
  64. package/dist/lens/index.mjs.map +1 -0
  65. package/dist/map/index.cjs +86 -0
  66. package/dist/map/index.cjs.map +1 -0
  67. package/dist/map/index.d.cts +41 -0
  68. package/dist/map/index.d.cts.map +1 -0
  69. package/dist/map/index.d.mts +41 -0
  70. package/dist/map/index.d.mts.map +1 -0
  71. package/dist/map/index.mjs +75 -0
  72. package/dist/map/index.mjs.map +1 -0
  73. package/dist/number/index.cjs +179 -0
  74. package/dist/number/index.cjs.map +1 -0
  75. package/dist/number/index.d.cts +112 -0
  76. package/dist/number/index.d.cts.map +1 -0
  77. package/dist/number/index.d.mts +112 -0
  78. package/dist/number/index.d.mts.map +1 -0
  79. package/dist/number/index.mjs +159 -0
  80. package/dist/number/index.mjs.map +1 -0
  81. package/dist/object/index.cjs +190 -0
  82. package/dist/object/index.cjs.map +1 -0
  83. package/dist/object/index.d.cts +118 -0
  84. package/dist/object/index.d.cts.map +1 -0
  85. package/dist/object/index.d.mts +118 -0
  86. package/dist/object/index.d.mts.map +1 -0
  87. package/dist/object/index.mjs +169 -0
  88. package/dist/object/index.mjs.map +1 -0
  89. package/dist/orThrow-V91Jw2lF.mjs +15 -0
  90. package/dist/orThrow-V91Jw2lF.mjs.map +1 -0
  91. package/dist/orThrow-ejzcQYAI.cjs +20 -0
  92. package/dist/orThrow-ejzcQYAI.cjs.map +1 -0
  93. package/dist/order/index.cjs +50 -0
  94. package/dist/order/index.cjs.map +1 -0
  95. package/dist/order/index.d.cts +3 -0
  96. package/dist/order/index.d.mts +3 -0
  97. package/dist/order/index.mjs +42 -0
  98. package/dist/order/index.mjs.map +1 -0
  99. package/dist/order.constants-BWSCg3C7.d.cts +11 -0
  100. package/dist/order.constants-BWSCg3C7.d.cts.map +1 -0
  101. package/dist/order.constants-BWSCg3C7.d.mts +11 -0
  102. package/dist/order.constants-BWSCg3C7.d.mts.map +1 -0
  103. package/dist/purry-B2_0DGLV.cjs +28 -0
  104. package/dist/purry-B2_0DGLV.cjs.map +1 -0
  105. package/dist/purry-BOWmqwDB.mjs +23 -0
  106. package/dist/purry-BOWmqwDB.mjs.map +1 -0
  107. package/dist/set/index.cjs +131 -0
  108. package/dist/set/index.cjs.map +1 -0
  109. package/dist/set/index.d.cts +61 -0
  110. package/dist/set/index.d.cts.map +1 -0
  111. package/dist/set/index.d.mts +61 -0
  112. package/dist/set/index.d.mts.map +1 -0
  113. package/dist/set/index.mjs +115 -0
  114. package/dist/set/index.mjs.map +1 -0
  115. package/dist/string/index.cjs +288 -0
  116. package/dist/string/index.cjs.map +1 -0
  117. package/dist/string/index.d.cts +144 -0
  118. package/dist/string/index.d.cts.map +1 -0
  119. package/dist/string/index.d.mts +144 -0
  120. package/dist/string/index.d.mts.map +1 -0
  121. package/dist/string/index.mjs +254 -0
  122. package/dist/string/index.mjs.map +1 -0
  123. package/dist/tuple/index.cjs +135 -0
  124. package/dist/tuple/index.cjs.map +1 -0
  125. package/dist/tuple/index.d.cts +207 -0
  126. package/dist/tuple/index.d.cts.map +1 -0
  127. package/dist/tuple/index.d.mts +207 -0
  128. package/dist/tuple/index.d.mts.map +1 -0
  129. package/dist/tuple/index.mjs +122 -0
  130. package/dist/tuple/index.mjs.map +1 -0
  131. package/dist/types-D8f67ZCe.d.cts +54 -0
  132. package/dist/types-D8f67ZCe.d.cts.map +1 -0
  133. package/dist/types-D8f67ZCe.d.mts +54 -0
  134. package/dist/types-D8f67ZCe.d.mts.map +1 -0
  135. package/package.json +177 -0
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2025 Harris Miller
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # @ts-fns/stdlib
2
+
3
+ ## Core concepts
4
+
5
+ * Functional Programming style API
6
+ * Stand-alone functions
7
+ * Fully type-safe
8
+ * Immutability, with appropriate exceptions
9
+ * Normalized return types to `Error | T` unions
10
+ * pipe/compose work like ADT `map`/`flatMap` under the hood
11
+ * Interoperable with other FP focused libraries!
12
+
13
+ Elixir style everything, for consistent, clean, and type-safe code
14
+
15
+ ## Usage
16
+
17
+ Very much a Work in progress
18
+
19
+ Still working on the standard alias
20
+
21
+ ```typescript
22
+ import * as Arr from '@ts-fns/stdlib/array';
23
+ import * as Func from '@ts-fns/stdlib/function';
24
+ import * as Guard from '@ts-fns/stdlib/guard';
25
+ import * as Iter from '@ts-fns/stdlib/iterator';
26
+ import * as Lens from '@ts-fns/stdlib/lens';
27
+ import * as Map from '@ts-fns/stdlib/map';
28
+ import * as Num from '@ts-fns/stdlib/number';
29
+ import * as Obj from '@ts-fns/stdlib/object';
30
+ import * as Ord from '@ts-fns/stdlib/order';
31
+ import * as Set from '@ts-fns/stdlib/set';
32
+ import * as Str from '@ts-fns/stdlib/string';
33
+ import * as Tuple from '@ts-fns/stdlib/tuple';
34
+ ```
35
+
36
+ ## Details
37
+
38
+ ### Normalized return types to `Error | T` unions
39
+
40
+ Javascript has no normalized "Empty" value that gets returned from methods. `-1`? `undefined`? `null`?. In addition, while exceptions and try/catch blocks are the built-in mechanisms for Errors, sometimes those errors are represented as values. For example, `Number.parseInt()` returns `NaN` instead of throwing.
41
+
42
+ Errors-as-values in the form of unions are the most idiomatic way to continue to use javascript without introducing new paradigms such as `Result`. Control-flow logic doesn't change in most cases, you just change your condition parameters
43
+
44
+ ```typescript
45
+ /* vanilla js */
46
+ const user = users.find(u => u.id === id);
47
+ // ^? User | undefined
48
+
49
+ if (user === undefined) {
50
+ // handle "NotFound" case
51
+ }
52
+
53
+ /* @ts-fns/stdlib */
54
+ import * as Arr from '@ts-fns/stdlib/array';
55
+
56
+ const user = Arr.find(users, u => u.id === id);
57
+ // ^? User | NotFoundError
58
+
59
+ if (user instanceof NotFoundError) {
60
+ // handle "NotFound" case
61
+ }
62
+ ```
63
+
64
+ While functions that throw get changed from try-catch blocks to other control-flow mechanics, this is probably for the better, as it aligns into a single paradigm flow
65
+
66
+ ```typescript
67
+ /* vanilla js */
68
+ let updatedUsers;
69
+ try {
70
+ updatedUsers = users.with(5, updatedUser);
71
+ } catch(e) {
72
+ // handle error
73
+ }
74
+
75
+ /* @ts-fns/stdlib */
76
+ import * as Arr from '@ts-fns/stdlib/array';
77
+
78
+ const updatedUsers = Arr.insert(users, 5, updatedUser)
79
+
80
+ if (updatedUsers instanceof RangeError) {
81
+ // handle error
82
+ }
83
+ ```
84
+
85
+ Errors are no longer opaque, and compliment Typescript's type system. Yielding more type-safety and less error prone code.
86
+
87
+ ### Two Type of Errors
88
+
89
+ This repo subscribes to Effect's philosophy that there are Expected and Unexpected Errors (read about it here: https://effect.website/docs/guide/effects/errors).
90
+
91
+ Just like Effect does not track Unexpected Errors, neither does `@ts-fns/stdlib`. In particular, this library only captures expected errors, returning them as values. Unexpected errors are thrown as normal.
92
+
93
+ #### Expected Errors
94
+
95
+ Some examples
96
+
97
+ * `Array.prototype.with()` throws a `RangeError` if the index is out of bounds. `Arr.update()` returns `RangeError` as a value for the same reason.
98
+ * Different value are used to represent "not found". `Arr.indexOf()` returns `-1`. `Arr.find()` returns `undefined`. `Str.match()` returns `null`. `@ts-fns/stdlib` normalizes these by returning `NotFoundError` as a value
99
+ * Array function that would normally return when called on an empty array will return `EmptyArrayError` instead.
100
+
101
+ All functions that catch, or add, expected Errors will return that errors as a value, typed as part of that function's return type union.
102
+
103
+ ##### Type narrowing to remove errors from return type
104
+
105
+ `Arr.first()` returns `EmptyArrayError | T`. The guard function `Arr.isNotEmpty()` validates at runtime that an array is not empty and narrow an array `T[]` to `NonEmptyArray<T>`. `Arr.first()` is typed to accept `ReadonlyNonEmptyArray<T>` and will return only `T` for that case. This allows you to remove errors from the return type by validating at runtime that the error condition cannot exist.
106
+
107
+ ```typescript
108
+ import * as Arr from '@ts-fns/stdlib/array';
109
+
110
+ const arr: number[] = [];
111
+
112
+ const first = Arr.first(arr);
113
+ // ^? EmptyArrayError | number
114
+
115
+ if (Arr.isNotEmpty(arr)) {
116
+ const first = Arr.first(arr);
117
+ // ^? number
118
+ }
119
+ ```
120
+
121
+ #### Unexpected Errors
122
+
123
+ `Str.startsWith()` is a good example. Javascript's `String.prototype.startsWith()` [throws an TypeError if the search value is a regex](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith#exceptions). Though defined, this error is considered *unexpected* because it would be illogical to use a regex. Javascript coerces other types to strings, Typescript defines `string` as the only valid argument type.
124
+
125
+ Any function that does this will have `@throws` in their JSDoc comment to indicate this possibility.
126
+
127
+ ### TODO
128
+
129
+ Go over:
130
+ * `.assert()` to remove errors from the return types but with the risk of throwing
131
+ * `gen()` function to utilize generator functions to write procedural code and aggregate error handle to the result
132
+ * `pipe`/`compose` act like ADT `.map()`/`.flatMap()` under-the-hood, allowing you to string together functions that throw error, but defer those errors to the result
@@ -0,0 +1,551 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_orThrow = require("../orThrow-ejzcQYAI.cjs");
3
+ const require_purry = require("../purry-B2_0DGLV.cjs");
4
+ const require_errors = require("../errors-O-d_Vemi.cjs");
5
+ require("../function-CB82a2GS.cjs");
6
+ //#region src/array/_globalAliases.ts
7
+ const { from, fromAsync, isArray, of } = Array;
8
+ const arrayConstructor = Array;
9
+ //#endregion
10
+ //#region src/array/at.ts
11
+ /**
12
+ * Internal method that wraps `arr.at()` but throws the same `RangeError` that `arr.with()` does
13
+ * @throws {RangeError}
14
+ */
15
+ function atImplementation(arr, index) {
16
+ if (arr.length === 0 || index >= arr.length || index < -arr.length) return /* @__PURE__ */ new RangeError(`Arr.at() :: Invalid index : ${index}`);
17
+ return arr.at(index);
18
+ }
19
+ function at(...args) {
20
+ return require_purry.purry(atImplementation, args);
21
+ }
22
+ function atAssert(...args) {
23
+ return require_purry.purry(require_orThrow.orThrow(atImplementation), args);
24
+ }
25
+ at.assert = atAssert;
26
+ //#endregion
27
+ //#region src/array/chunk.ts
28
+ function chunkImplementation(arr, size) {
29
+ if (size < 1) throw new RangeError(`Arr.chunk() :: ${size} must be a positive integer`);
30
+ if (arr.length === 0) return [];
31
+ if (size >= arr.length) return [[...arr]];
32
+ const chunks = Math.ceil(arr.length / size);
33
+ if (size === 1) return arr.map((v) => [v]);
34
+ return Array(chunks).fill(void 0).map((_, index) => {
35
+ const start = index * size;
36
+ return arr.slice(start, start + size);
37
+ });
38
+ }
39
+ function chunk(...args) {
40
+ return require_purry.purry(chunkImplementation, args);
41
+ }
42
+ function chunkAssert(...args) {
43
+ return require_purry.purry(require_orThrow.orThrow(chunkImplementation), args);
44
+ }
45
+ chunk.assert = chunkAssert;
46
+ //#endregion
47
+ //#region src/array/concat.ts
48
+ function concatImplementation(arr, other) {
49
+ return [...arr, ...other];
50
+ }
51
+ function concat(...args) {
52
+ return require_purry.purry(concatImplementation, args);
53
+ }
54
+ //#endregion
55
+ //#region src/array/drop.ts
56
+ function dropImplementation(arr, n) {
57
+ return arr.slice(n);
58
+ }
59
+ function drop(...args) {
60
+ return require_purry.purry(dropImplementation, args);
61
+ }
62
+ //#endregion
63
+ //#region src/array/every.ts
64
+ function everyImplementation(arr, predicate) {
65
+ return arr.every(predicate);
66
+ }
67
+ function every(...args) {
68
+ return require_purry.purry(everyImplementation, args);
69
+ }
70
+ //#endregion
71
+ //#region src/array/find.ts
72
+ function findImplementation(arr, predicate) {
73
+ const foundIndex = arr.findIndex(predicate);
74
+ if (foundIndex === -1) return new require_errors.NotFoundError("Arr.find :: predicate found no match.");
75
+ return arr[foundIndex];
76
+ }
77
+ function find(...args) {
78
+ return require_purry.purry(findImplementation, args);
79
+ }
80
+ function findAssert(...args) {
81
+ return require_purry.purry(require_orThrow.orThrow(findImplementation), args);
82
+ }
83
+ find.assert = findAssert;
84
+ //#endregion
85
+ //#region src/array/findIndex.ts
86
+ function findIndexImplementation(arr, predicate) {
87
+ const result = arr.findIndex(predicate);
88
+ if (result === -1) return new require_errors.NotFoundError("Arr.findIndex.orError() :: predicate found no match.");
89
+ return result;
90
+ }
91
+ function findIndex(...args) {
92
+ return require_purry.purry(findIndexImplementation, args);
93
+ }
94
+ function findIndexAssert(...args) {
95
+ return require_purry.purry(require_orThrow.orThrow(findIndexImplementation), args);
96
+ }
97
+ findIndex.assert = findIndexAssert;
98
+ //#endregion
99
+ //#region src/array/findLast.ts
100
+ function findLastImplementation(arr, predicate) {
101
+ const foundIndex = arr.findLastIndex(predicate);
102
+ if (foundIndex === -1) return new require_errors.NotFoundError("Arr.findLast() :: predicate found no match.");
103
+ return arr[foundIndex];
104
+ }
105
+ function findLast(...args) {
106
+ return require_purry.purry(findLastImplementation, args);
107
+ }
108
+ function findLastAssert(...args) {
109
+ return require_purry.purry(require_orThrow.orThrow(findLastImplementation), args);
110
+ }
111
+ findLast.assert = findLastAssert;
112
+ //#endregion
113
+ //#region src/array/findLastIndex.ts
114
+ function findLastIndexImplementation(arr, predicate) {
115
+ const result = arr.findLastIndex(predicate);
116
+ if (result === -1) return new require_errors.NotFoundError("Arr.findLastIndex() :: predicate found no match.");
117
+ return result;
118
+ }
119
+ function findLastIndex(...args) {
120
+ return require_purry.purry(findLastIndexImplementation, args);
121
+ }
122
+ function findLastIndexAssert(...args) {
123
+ return require_purry.purry(require_orThrow.orThrow(findLastIndexImplementation), args);
124
+ }
125
+ findLastIndex.assert = findLastIndexAssert;
126
+ //#endregion
127
+ //#region src/array/first.ts
128
+ function first(arr) {
129
+ if (arr.length === 0) return new require_errors.EmptyArrayError("Arr.first() :: array is empty");
130
+ return arr[0];
131
+ }
132
+ function firstAssert(arr) {
133
+ return require_orThrow.orThrow(first)(arr);
134
+ }
135
+ first.assert = firstAssert;
136
+ //#endregion
137
+ //#region src/array/flatMap.ts
138
+ function flatMapImplementation(arr, callbackfn) {
139
+ return arr.flatMap(callbackfn);
140
+ }
141
+ function flatMap(...args) {
142
+ return require_purry.purry(flatMapImplementation, args);
143
+ }
144
+ //#endregion
145
+ //#region src/array/forEach.ts
146
+ function forEachImplementation(arr, callbackfn) {
147
+ arr.forEach(callbackfn);
148
+ return arr;
149
+ }
150
+ function forEach(...args) {
151
+ return require_purry.purry(forEachImplementation, args);
152
+ }
153
+ //#endregion
154
+ //#region src/array/init.ts
155
+ /**
156
+ *
157
+ */
158
+ function init(arr) {
159
+ return arr.slice(0, arr.length - 1);
160
+ }
161
+ function initAssert(arr) {
162
+ return require_orThrow.orThrow(init)(arr);
163
+ }
164
+ init.assert = initAssert;
165
+ //#endregion
166
+ //#region src/array/insert.ts
167
+ function insertImplementation(arr, index, value) {
168
+ try {
169
+ return arr.with(index, value);
170
+ } catch (_e) {
171
+ return /* @__PURE__ */ new RangeError(`Arr.insert() - Invalid index : ${index}`);
172
+ }
173
+ }
174
+ function insert(...args) {
175
+ return require_purry.purry(insertImplementation, args);
176
+ }
177
+ function insertAssert(...args) {
178
+ return require_purry.purry(require_orThrow.orThrow(insertImplementation), args);
179
+ }
180
+ insert.assert = insertAssert;
181
+ //#endregion
182
+ //#region src/array/isEmpty.ts
183
+ function isNotEmpty(arr) {
184
+ return arr.length > 0;
185
+ }
186
+ function isEmpty(arr) {
187
+ return arr.length === 0;
188
+ }
189
+ //#endregion
190
+ //#region src/array/join.ts
191
+ function joinImplementation(arr, separator) {
192
+ return arr.join(separator);
193
+ }
194
+ function join(...args) {
195
+ return require_purry.purry(joinImplementation, args);
196
+ }
197
+ //#endregion
198
+ //#region src/array/last.ts
199
+ function last(arr) {
200
+ if (arr.length === 0) return new require_errors.EmptyArrayError("Arr.last() :: array is empty");
201
+ return arr[arr.length - 1];
202
+ }
203
+ function lastAssert(arr) {
204
+ return require_orThrow.orThrow(last)(arr);
205
+ }
206
+ last.assert = lastAssert;
207
+ //#endregion
208
+ //#region src/array/length.ts
209
+ /**
210
+ * Returns length of array
211
+ * @param arr
212
+ * @returns
213
+ */
214
+ function length(arr) {
215
+ return arr.length;
216
+ }
217
+ //#endregion
218
+ //#region src/array/map.ts
219
+ function mapImplementation(arr, callbackfn) {
220
+ return arr.map(callbackfn);
221
+ }
222
+ function map(...args) {
223
+ return require_purry.purry(mapImplementation, args);
224
+ }
225
+ //#endregion
226
+ //#region src/array/ofLength.ts
227
+ /**
228
+ * Arr.ofLength
229
+ *
230
+ * @throws {RangeError}
231
+ */
232
+ function ofLength(arrayLength) {
233
+ return Array(arrayLength);
234
+ }
235
+ //#endregion
236
+ //#region src/array/partition.ts
237
+ function partitionImplementation(arr, predicate) {
238
+ const len = arr.length;
239
+ const left = [];
240
+ const right = [];
241
+ for (let i = 0; i < len; i += 1) {
242
+ const value = arr[i];
243
+ if (predicate(value, i, arr)) left.push(value);
244
+ else right.push(value);
245
+ }
246
+ return [left, right];
247
+ }
248
+ function partition(...args) {
249
+ return require_purry.purry(partitionImplementation, args);
250
+ }
251
+ //#endregion
252
+ //#region src/array/pop.ts
253
+ function pop(arr) {
254
+ if (arr.length === 0) return new require_errors.EmptyArrayError("Arr.pop() :: array is empty");
255
+ const lastIndex = arr.length - 1;
256
+ return [arr[lastIndex], arr.slice(0, lastIndex)];
257
+ }
258
+ function popAssert(arr) {
259
+ return require_orThrow.orThrow(pop)(arr);
260
+ }
261
+ pop.assert = popAssert;
262
+ //#endregion
263
+ //#region src/array/prepend.ts
264
+ function prependImplementation(arr, other) {
265
+ return [...other, ...arr];
266
+ }
267
+ function prepend(...args) {
268
+ return require_purry.purry(prependImplementation, args);
269
+ }
270
+ //#endregion
271
+ //#region src/array/push.ts
272
+ function pushImplementation(arr, value) {
273
+ return [...arr, value];
274
+ }
275
+ function push(...args) {
276
+ return require_purry.purry(pushImplementation, args);
277
+ }
278
+ //#endregion
279
+ //#region src/array/reduce.ts
280
+ function reduceImplementation(arr, callbackFn, initialValue) {
281
+ return arr.reduce(callbackFn, initialValue);
282
+ }
283
+ function reduce(...args) {
284
+ return require_purry.purry(reduceImplementation, args);
285
+ }
286
+ //#endregion
287
+ //#region src/array/reduce1.ts
288
+ function reduce1Implementation(arr, callbackFn) {
289
+ return arr.reduce(callbackFn);
290
+ }
291
+ function reduce1(...args) {
292
+ return require_purry.purry(reduce1Implementation, args);
293
+ }
294
+ //#endregion
295
+ //#region src/array/reduceRight.ts
296
+ function reduceRightImplementation(arr, callbackFn, initialValue) {
297
+ return arr.reduceRight(callbackFn, initialValue);
298
+ }
299
+ function reduceRight(...args) {
300
+ return require_purry.purry(reduceRightImplementation, args);
301
+ }
302
+ //#endregion
303
+ //#region src/array/reduceRight1.ts
304
+ function reduceRight1Implementation(arr, callbackFn) {
305
+ return arr.reduceRight(callbackFn);
306
+ }
307
+ function reduceRight1(...args) {
308
+ return require_purry.purry(reduceRight1Implementation, args);
309
+ }
310
+ //#endregion
311
+ //#region src/array/rest.ts
312
+ /**
313
+ * Returns an array excluding the first entry
314
+ * @param arr
315
+ * @returns
316
+ */
317
+ function rest(arr) {
318
+ const [, ...tail] = arr;
319
+ return tail;
320
+ }
321
+ //#endregion
322
+ //#region src/array/reverse.ts
323
+ function reverseImplementation(arr) {
324
+ return arr.toReversed();
325
+ }
326
+ function reverse(...args) {
327
+ return require_purry.purry(reverseImplementation, args);
328
+ }
329
+ //#endregion
330
+ //#region src/array/scan.ts
331
+ function scanImplementation(arr, callbackFn, initialValue) {
332
+ const len = arr.length;
333
+ const result = Array(len + 1);
334
+ let acc = initialValue;
335
+ result[0] = acc;
336
+ for (let index = 0; index < len; index += 1) {
337
+ acc = callbackFn(acc, arr[index], index, arr);
338
+ result[index + 1] = acc;
339
+ }
340
+ return result;
341
+ }
342
+ function scan(...args) {
343
+ return require_purry.purry(scanImplementation, args);
344
+ }
345
+ //#endregion
346
+ //#region src/array/shift.ts
347
+ function shift(arr) {
348
+ if (arr.length === 0) return new require_errors.EmptyArrayError("Arr.shift() :: array is empty");
349
+ const [head, ...tail] = arr;
350
+ return [head, tail];
351
+ }
352
+ function shiftAssert(arr) {
353
+ return require_orThrow.orThrow(shift)(arr);
354
+ }
355
+ shift.assert = shiftAssert;
356
+ //#endregion
357
+ //#region src/array/shuffle.ts
358
+ function shuffle(arr) {
359
+ const result = [...arr];
360
+ const len = result.length;
361
+ for (let i = 0; i < len; i += 1) {
362
+ const rand = i + Math.floor(Math.random() * (len - i));
363
+ const value = result[rand];
364
+ result[rand] = result[i];
365
+ result[i] = value;
366
+ }
367
+ return result;
368
+ }
369
+ //#endregion
370
+ //#region src/array/some.ts
371
+ function someImplementation(arr, predicate) {
372
+ return arr.some(predicate);
373
+ }
374
+ function some(...args) {
375
+ return require_purry.purry(someImplementation, args);
376
+ }
377
+ //#endregion
378
+ //#region src/array/sort.ts
379
+ function sortImplementation(arr, compareFn) {
380
+ return arr.toSorted(compareFn);
381
+ }
382
+ function sort(...args) {
383
+ return require_purry.purry(sortImplementation, args);
384
+ }
385
+ //#endregion
386
+ //#region src/array/sortBy.ts
387
+ function sortByImplementation(arr, mapFn) {
388
+ return arr.toSorted((left, right) => {
389
+ const l = mapFn(left);
390
+ const r = mapFn(right);
391
+ if (l < r) return -1;
392
+ if (l > r) return 0;
393
+ return 0;
394
+ });
395
+ }
396
+ function sortBy(...args) {
397
+ return require_purry.purry(sortByImplementation, args);
398
+ }
399
+ //#endregion
400
+ //#region src/array/take.ts
401
+ function takeImplementation(arr, limit) {
402
+ if (limit < 1) throw new RangeError(`Arr.take() :: ${limit} must be a positive integer`);
403
+ return arr.slice(0, limit);
404
+ }
405
+ function take(...args) {
406
+ return require_purry.purry(takeImplementation, args);
407
+ }
408
+ //#endregion
409
+ //#region src/array/transpose.ts
410
+ function transpose(arr) {
411
+ const maxLen = arr.reduce((acc, inner) => Math.max(acc, inner.length), 0);
412
+ return Array(maxLen).fill(void 0).map((_, index) => arr.map((inner) => inner[index]));
413
+ }
414
+ //#endregion
415
+ //#region src/array/unique.ts
416
+ function unique(arr) {
417
+ if (arr.length === 0) return [];
418
+ return Array.from(new Set(arr));
419
+ }
420
+ //#endregion
421
+ //#region src/array/uniqueBy.ts
422
+ function uniqueByImplementation(arr, mapFn) {
423
+ if (arr.length === 0) return [];
424
+ const map = /* @__PURE__ */ new Map();
425
+ arr.forEach((_, index) => {
426
+ const value = arr[index];
427
+ const key = mapFn(value);
428
+ if (!map.has(key)) map.set(key, value);
429
+ });
430
+ return Array.from(map.values());
431
+ }
432
+ function uniqueBy(...args) {
433
+ return require_purry.purry(uniqueByImplementation, args);
434
+ }
435
+ //#endregion
436
+ //#region src/array/uniqueWith.ts
437
+ function uniqueWith(arr, isEqual) {
438
+ if (arr.length === 0) return [];
439
+ return arr.filter((value, index) => {
440
+ return index === (arr.find((otherValue, otherIndex) => index === otherIndex || isEqual(value, otherValue)) ?? -1);
441
+ });
442
+ }
443
+ //#endregion
444
+ //#region src/array/unshift.ts
445
+ function unshiftImplementation(arr, value) {
446
+ return [value, ...arr];
447
+ }
448
+ function unshift(...args) {
449
+ return require_purry.purry(unshiftImplementation, args);
450
+ }
451
+ //#endregion
452
+ //#region src/array/update.ts
453
+ function updateImplementation(arr, index, fn) {
454
+ if (index >= arr.length || index < -arr.length) return /* @__PURE__ */ new RangeError(`Arr.update() :: Invalid index : ${index}`);
455
+ const updatedValue = fn(arr.at(index));
456
+ return arr.with(index, updatedValue);
457
+ }
458
+ function update(...args) {
459
+ return require_purry.purry(updateImplementation, args);
460
+ }
461
+ function updateAssert(...args) {
462
+ return require_purry.purry(require_orThrow.orThrow(updateImplementation), args);
463
+ }
464
+ update.assert = updateAssert;
465
+ //#endregion
466
+ //#region src/array/window.ts
467
+ function windowImplementation(arr, size) {
468
+ if (size < 1) throw new RangeError(`Arr.window() :: ${size} must be a positive integer`);
469
+ const limit = arr.length - (size - 1);
470
+ if (limit < 0) return [];
471
+ return Array(limit).fill(void 0).map((_, index) => arr.slice(index, index + size));
472
+ }
473
+ function window(...args) {
474
+ return require_purry.purry(windowImplementation, args);
475
+ }
476
+ function windowAssert(...args) {
477
+ return require_purry.purry(require_orThrow.orThrow(windowImplementation), args);
478
+ }
479
+ window.assert = windowAssert;
480
+ //#endregion
481
+ //#region src/array/zip.ts
482
+ function zipImplementation(arr, other) {
483
+ return Array(Math.min(arr.length, other.length)).fill(void 0).map((_, index) => [arr[index], other[index]]);
484
+ }
485
+ function zip(...args) {
486
+ return require_purry.purry(zipImplementation, args);
487
+ }
488
+ //#endregion
489
+ //#region src/array/zipWith.ts
490
+ function zipWithImplementation(arr, other, fn) {
491
+ return Array(Math.min(arr.length, other.length)).fill(void 0).map((_, index) => fn(arr[index], other[index]));
492
+ }
493
+ function zipWith(...args) {
494
+ return require_purry.purry(zipWithImplementation, args);
495
+ }
496
+ //#endregion
497
+ exports.Array = arrayConstructor;
498
+ exports.at = at;
499
+ exports.atAssert = atAssert;
500
+ exports.chunk = chunk;
501
+ exports.concat = concat;
502
+ exports.drop = drop;
503
+ exports.every = every;
504
+ exports.find = find;
505
+ exports.findIndex = findIndex;
506
+ exports.findLast = findLast;
507
+ exports.findLastIndex = findLastIndex;
508
+ exports.first = first;
509
+ exports.flatMap = flatMap;
510
+ exports.forEach = forEach;
511
+ exports.from = from;
512
+ exports.fromAsync = fromAsync;
513
+ exports.init = init;
514
+ exports.insert = insert;
515
+ exports.isArray = isArray;
516
+ exports.isEmpty = isEmpty;
517
+ exports.isNotEmpty = isNotEmpty;
518
+ exports.join = join;
519
+ exports.last = last;
520
+ exports.length = length;
521
+ exports.map = map;
522
+ exports.of = of;
523
+ exports.ofLength = ofLength;
524
+ exports.partition = partition;
525
+ exports.pop = pop;
526
+ exports.prepend = prepend;
527
+ exports.push = push;
528
+ exports.reduce = reduce;
529
+ exports.reduce1 = reduce1;
530
+ exports.reduceRight = reduceRight;
531
+ exports.reduceRight1 = reduceRight1;
532
+ exports.rest = rest;
533
+ exports.reverse = reverse;
534
+ exports.scan = scan;
535
+ exports.shift = shift;
536
+ exports.shuffle = shuffle;
537
+ exports.some = some;
538
+ exports.sort = sort;
539
+ exports.sortBy = sortBy;
540
+ exports.take = take;
541
+ exports.transpose = transpose;
542
+ exports.unique = unique;
543
+ exports.uniqueBy = uniqueBy;
544
+ exports.uniqueWith = uniqueWith;
545
+ exports.unshift = unshift;
546
+ exports.update = update;
547
+ exports.window = window;
548
+ exports.zip = zip;
549
+ exports.zipWith = zipWith;
550
+
551
+ //# sourceMappingURL=index.cjs.map