@nlozgachev/pipelined 0.12.0 → 0.13.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 (205) hide show
  1. package/LICENCE +28 -0
  2. package/README.md +1 -1
  3. package/{types/src/Types/NonEmptyList.d.ts → dist/NonEmptyList-BlGFjor5.d.mts} +4 -3
  4. package/dist/NonEmptyList-BlGFjor5.d.ts +30 -0
  5. package/dist/Task-BB8Wmc1J.d.ts +677 -0
  6. package/dist/Task-ChKyH0pF.d.mts +677 -0
  7. package/dist/chunk-DBIC62UV.mjs +6 -0
  8. package/dist/chunk-QPTGO5AS.mjs +150 -0
  9. package/dist/composition.d.mts +495 -0
  10. package/dist/composition.d.ts +495 -0
  11. package/dist/composition.js +188 -0
  12. package/dist/composition.mjs +135 -0
  13. package/dist/core.d.mts +2170 -0
  14. package/dist/core.d.ts +2170 -0
  15. package/dist/core.js +698 -0
  16. package/dist/core.mjs +517 -0
  17. package/dist/types.d.mts +54 -0
  18. package/{types/src/Types/Brand.d.ts → dist/types.d.ts} +6 -4
  19. package/dist/types.js +41 -0
  20. package/dist/types.mjs +14 -0
  21. package/dist/utils.d.mts +1285 -0
  22. package/dist/utils.d.ts +1285 -0
  23. package/dist/utils.js +722 -0
  24. package/dist/utils.mjs +553 -0
  25. package/package.json +63 -69
  26. package/esm/mod.js +0 -3
  27. package/esm/package.json +0 -3
  28. package/esm/src/Composition/compose.js +0 -3
  29. package/esm/src/Composition/converge.js +0 -3
  30. package/esm/src/Composition/curry.js +0 -42
  31. package/esm/src/Composition/flip.js +0 -20
  32. package/esm/src/Composition/flow.js +0 -8
  33. package/esm/src/Composition/fn.js +0 -85
  34. package/esm/src/Composition/index.js +0 -13
  35. package/esm/src/Composition/juxt.js +0 -3
  36. package/esm/src/Composition/memoize.js +0 -66
  37. package/esm/src/Composition/not.js +0 -25
  38. package/esm/src/Composition/on.js +0 -12
  39. package/esm/src/Composition/pipe.js +0 -3
  40. package/esm/src/Composition/tap.js +0 -33
  41. package/esm/src/Composition/uncurry.js +0 -32
  42. package/esm/src/Core/Deferred.js +0 -30
  43. package/esm/src/Core/InternalTypes.js +0 -1
  44. package/esm/src/Core/Lens.js +0 -98
  45. package/esm/src/Core/Logged.js +0 -111
  46. package/esm/src/Core/Option.js +0 -191
  47. package/esm/src/Core/Optional.js +0 -160
  48. package/esm/src/Core/Predicate.js +0 -133
  49. package/esm/src/Core/Reader.js +0 -134
  50. package/esm/src/Core/Refinement.js +0 -115
  51. package/esm/src/Core/RemoteData.js +0 -211
  52. package/esm/src/Core/Result.js +0 -170
  53. package/esm/src/Core/State.js +0 -181
  54. package/esm/src/Core/Task.js +0 -223
  55. package/esm/src/Core/TaskOption.js +0 -106
  56. package/esm/src/Core/TaskResult.js +0 -127
  57. package/esm/src/Core/TaskValidation.js +0 -128
  58. package/esm/src/Core/These.js +0 -245
  59. package/esm/src/Core/Tuple.js +0 -112
  60. package/esm/src/Core/Validation.js +0 -212
  61. package/esm/src/Core/index.js +0 -18
  62. package/esm/src/Types/Brand.js +0 -28
  63. package/esm/src/Types/NonEmptyList.js +0 -14
  64. package/esm/src/Types/index.js +0 -2
  65. package/esm/src/Utils/Arr.js +0 -570
  66. package/esm/src/Utils/Dict.js +0 -421
  67. package/esm/src/Utils/Num.js +0 -124
  68. package/esm/src/Utils/Rec.js +0 -241
  69. package/esm/src/Utils/Str.js +0 -134
  70. package/esm/src/Utils/Uniq.js +0 -265
  71. package/esm/src/Utils/index.js +0 -6
  72. package/script/mod.js +0 -19
  73. package/script/package.json +0 -3
  74. package/script/src/Composition/compose.js +0 -6
  75. package/script/src/Composition/converge.js +0 -6
  76. package/script/src/Composition/curry.js +0 -48
  77. package/script/src/Composition/flip.js +0 -24
  78. package/script/src/Composition/flow.js +0 -11
  79. package/script/src/Composition/fn.js +0 -98
  80. package/script/src/Composition/index.js +0 -29
  81. package/script/src/Composition/juxt.js +0 -6
  82. package/script/src/Composition/memoize.js +0 -71
  83. package/script/src/Composition/not.js +0 -29
  84. package/script/src/Composition/on.js +0 -16
  85. package/script/src/Composition/pipe.js +0 -6
  86. package/script/src/Composition/tap.js +0 -37
  87. package/script/src/Composition/uncurry.js +0 -38
  88. package/script/src/Core/Deferred.js +0 -33
  89. package/script/src/Core/InternalTypes.js +0 -2
  90. package/script/src/Core/Lens.js +0 -101
  91. package/script/src/Core/Logged.js +0 -114
  92. package/script/src/Core/Option.js +0 -194
  93. package/script/src/Core/Optional.js +0 -163
  94. package/script/src/Core/Predicate.js +0 -136
  95. package/script/src/Core/Reader.js +0 -137
  96. package/script/src/Core/Refinement.js +0 -118
  97. package/script/src/Core/RemoteData.js +0 -214
  98. package/script/src/Core/Result.js +0 -173
  99. package/script/src/Core/State.js +0 -184
  100. package/script/src/Core/Task.js +0 -226
  101. package/script/src/Core/TaskOption.js +0 -109
  102. package/script/src/Core/TaskResult.js +0 -130
  103. package/script/src/Core/TaskValidation.js +0 -131
  104. package/script/src/Core/These.js +0 -248
  105. package/script/src/Core/Tuple.js +0 -115
  106. package/script/src/Core/Validation.js +0 -215
  107. package/script/src/Core/index.js +0 -34
  108. package/script/src/Types/Brand.js +0 -31
  109. package/script/src/Types/NonEmptyList.js +0 -18
  110. package/script/src/Types/index.js +0 -18
  111. package/script/src/Utils/Arr.js +0 -573
  112. package/script/src/Utils/Dict.js +0 -424
  113. package/script/src/Utils/Num.js +0 -127
  114. package/script/src/Utils/Rec.js +0 -244
  115. package/script/src/Utils/Str.js +0 -137
  116. package/script/src/Utils/Uniq.js +0 -268
  117. package/script/src/Utils/index.js +0 -22
  118. package/types/mod.d.ts +0 -4
  119. package/types/mod.d.ts.map +0 -1
  120. package/types/src/Composition/compose.d.ts +0 -33
  121. package/types/src/Composition/compose.d.ts.map +0 -1
  122. package/types/src/Composition/converge.d.ts +0 -21
  123. package/types/src/Composition/converge.d.ts.map +0 -1
  124. package/types/src/Composition/curry.d.ts +0 -43
  125. package/types/src/Composition/curry.d.ts.map +0 -1
  126. package/types/src/Composition/flip.d.ts +0 -21
  127. package/types/src/Composition/flip.d.ts.map +0 -1
  128. package/types/src/Composition/flow.d.ts +0 -56
  129. package/types/src/Composition/flow.d.ts.map +0 -1
  130. package/types/src/Composition/fn.d.ts +0 -76
  131. package/types/src/Composition/fn.d.ts.map +0 -1
  132. package/types/src/Composition/index.d.ts +0 -14
  133. package/types/src/Composition/index.d.ts.map +0 -1
  134. package/types/src/Composition/juxt.d.ts +0 -18
  135. package/types/src/Composition/juxt.d.ts.map +0 -1
  136. package/types/src/Composition/memoize.d.ts +0 -46
  137. package/types/src/Composition/memoize.d.ts.map +0 -1
  138. package/types/src/Composition/not.d.ts +0 -26
  139. package/types/src/Composition/not.d.ts.map +0 -1
  140. package/types/src/Composition/on.d.ts +0 -13
  141. package/types/src/Composition/on.d.ts.map +0 -1
  142. package/types/src/Composition/pipe.d.ts +0 -56
  143. package/types/src/Composition/pipe.d.ts.map +0 -1
  144. package/types/src/Composition/tap.d.ts +0 -31
  145. package/types/src/Composition/tap.d.ts.map +0 -1
  146. package/types/src/Composition/uncurry.d.ts +0 -54
  147. package/types/src/Composition/uncurry.d.ts.map +0 -1
  148. package/types/src/Core/Deferred.d.ts +0 -49
  149. package/types/src/Core/Deferred.d.ts.map +0 -1
  150. package/types/src/Core/InternalTypes.d.ts +0 -23
  151. package/types/src/Core/InternalTypes.d.ts.map +0 -1
  152. package/types/src/Core/Lens.d.ts +0 -118
  153. package/types/src/Core/Lens.d.ts.map +0 -1
  154. package/types/src/Core/Logged.d.ts +0 -126
  155. package/types/src/Core/Logged.d.ts.map +0 -1
  156. package/types/src/Core/Option.d.ts +0 -209
  157. package/types/src/Core/Option.d.ts.map +0 -1
  158. package/types/src/Core/Optional.d.ts +0 -158
  159. package/types/src/Core/Optional.d.ts.map +0 -1
  160. package/types/src/Core/Predicate.d.ts +0 -161
  161. package/types/src/Core/Predicate.d.ts.map +0 -1
  162. package/types/src/Core/Reader.d.ts +0 -156
  163. package/types/src/Core/Reader.d.ts.map +0 -1
  164. package/types/src/Core/Refinement.d.ts +0 -138
  165. package/types/src/Core/Refinement.d.ts.map +0 -1
  166. package/types/src/Core/RemoteData.d.ts +0 -197
  167. package/types/src/Core/RemoteData.d.ts.map +0 -1
  168. package/types/src/Core/Result.d.ts +0 -182
  169. package/types/src/Core/Result.d.ts.map +0 -1
  170. package/types/src/Core/State.d.ts +0 -192
  171. package/types/src/Core/State.d.ts.map +0 -1
  172. package/types/src/Core/Task.d.ts +0 -219
  173. package/types/src/Core/Task.d.ts.map +0 -1
  174. package/types/src/Core/TaskOption.d.ts +0 -121
  175. package/types/src/Core/TaskOption.d.ts.map +0 -1
  176. package/types/src/Core/TaskResult.d.ts +0 -119
  177. package/types/src/Core/TaskResult.d.ts.map +0 -1
  178. package/types/src/Core/TaskValidation.d.ts +0 -144
  179. package/types/src/Core/TaskValidation.d.ts.map +0 -1
  180. package/types/src/Core/These.d.ts +0 -225
  181. package/types/src/Core/These.d.ts.map +0 -1
  182. package/types/src/Core/Tuple.d.ts +0 -129
  183. package/types/src/Core/Tuple.d.ts.map +0 -1
  184. package/types/src/Core/Validation.d.ts +0 -203
  185. package/types/src/Core/Validation.d.ts.map +0 -1
  186. package/types/src/Core/index.d.ts +0 -19
  187. package/types/src/Core/index.d.ts.map +0 -1
  188. package/types/src/Types/Brand.d.ts.map +0 -1
  189. package/types/src/Types/NonEmptyList.d.ts.map +0 -1
  190. package/types/src/Types/index.d.ts +0 -3
  191. package/types/src/Types/index.d.ts.map +0 -1
  192. package/types/src/Utils/Arr.d.ts +0 -403
  193. package/types/src/Utils/Arr.d.ts.map +0 -1
  194. package/types/src/Utils/Dict.d.ts +0 -310
  195. package/types/src/Utils/Dict.d.ts.map +0 -1
  196. package/types/src/Utils/Num.d.ts +0 -110
  197. package/types/src/Utils/Num.d.ts.map +0 -1
  198. package/types/src/Utils/Rec.d.ts +0 -159
  199. package/types/src/Utils/Rec.d.ts.map +0 -1
  200. package/types/src/Utils/Str.d.ts +0 -128
  201. package/types/src/Utils/Str.d.ts.map +0 -1
  202. package/types/src/Utils/Uniq.d.ts +0 -179
  203. package/types/src/Utils/Uniq.d.ts.map +0 -1
  204. package/types/src/Utils/index.d.ts +0 -7
  205. package/types/src/Utils/index.d.ts.map +0 -1
@@ -1,241 +0,0 @@
1
- import { Option } from "../Core/Option.js";
2
- /**
3
- * Functional record/object utilities that compose well with pipe.
4
- * All functions are data-last and curried where applicable.
5
- *
6
- * @example
7
- * ```ts
8
- * pipe(
9
- * { a: 1, b: 2, c: 3 },
10
- * Rec.filter(n => n > 1),
11
- * Rec.map(n => n * 10)
12
- * ); // { b: 20, c: 30 }
13
- * ```
14
- */
15
- export var Rec;
16
- (function (Rec) {
17
- /**
18
- * Transforms each value in a record.
19
- *
20
- * @example
21
- * ```ts
22
- * pipe({ a: 1, b: 2 }, Rec.map(n => n * 2)); // { a: 2, b: 4 }
23
- * ```
24
- */
25
- Rec.map = (f) => (data) => {
26
- const keys = Object.keys(data);
27
- const vals = Object.values(data);
28
- const result = {};
29
- for (let i = 0; i < keys.length; i++) {
30
- result[keys[i]] = f(vals[i]);
31
- }
32
- return result;
33
- };
34
- /**
35
- * Transforms each value in a record, also receiving the key.
36
- *
37
- * @example
38
- * ```ts
39
- * pipe({ a: 1, b: 2 }, Rec.mapWithKey((k, v) => `${k}:${v}`));
40
- * // { a: "a:1", b: "b:2" }
41
- * ```
42
- */
43
- Rec.mapWithKey = (f) => (data) => {
44
- const keys = Object.keys(data);
45
- const vals = Object.values(data);
46
- const result = {};
47
- for (let i = 0; i < keys.length; i++) {
48
- result[keys[i]] = f(keys[i], vals[i]);
49
- }
50
- return result;
51
- };
52
- /**
53
- * Filters values in a record by a predicate.
54
- *
55
- * @example
56
- * ```ts
57
- * pipe({ a: 1, b: 2, c: 3 }, Rec.filter(n => n > 1)); // { b: 2, c: 3 }
58
- * ```
59
- */
60
- Rec.filter = (predicate) => (data) => {
61
- const keys = Object.keys(data);
62
- const vals = Object.values(data);
63
- const result = {};
64
- for (let i = 0; i < keys.length; i++) {
65
- if (predicate(vals[i]))
66
- result[keys[i]] = vals[i];
67
- }
68
- return result;
69
- };
70
- /**
71
- * Filters values in a record by a predicate that also receives the key.
72
- *
73
- * @example
74
- * ```ts
75
- * pipe({ a: 1, b: 2 }, Rec.filterWithKey((k, v) => k !== "a" && v > 0));
76
- * // { b: 2 }
77
- * ```
78
- */
79
- Rec.filterWithKey = (predicate) => (data) => {
80
- const keys = Object.keys(data);
81
- const vals = Object.values(data);
82
- const result = {};
83
- for (let i = 0; i < keys.length; i++) {
84
- if (predicate(keys[i], vals[i]))
85
- result[keys[i]] = vals[i];
86
- }
87
- return result;
88
- };
89
- /**
90
- * Looks up a value by key, returning Option.
91
- *
92
- * @example
93
- * ```ts
94
- * pipe({ a: 1, b: 2 }, Rec.lookup("a")); // Some(1)
95
- * pipe({ a: 1, b: 2 }, Rec.lookup("c")); // None
96
- * ```
97
- */
98
- Rec.lookup = (key) => (data) => Object.prototype.hasOwnProperty.call(data, key) ? Option.some(data[key]) : Option.none();
99
- /**
100
- * Returns all keys of a record.
101
- */
102
- Rec.keys = (data) => Object.keys(data);
103
- /**
104
- * Returns all values of a record.
105
- */
106
- Rec.values = (data) => Object.values(data);
107
- /**
108
- * Returns all key-value pairs of a record.
109
- */
110
- Rec.entries = (data) => Object.entries(data);
111
- /**
112
- * Creates a record from key-value pairs.
113
- *
114
- * @example
115
- * ```ts
116
- * Rec.fromEntries([["a", 1], ["b", 2]]); // { a: 1, b: 2 }
117
- * ```
118
- */
119
- Rec.fromEntries = (data) => Object.fromEntries(data);
120
- /**
121
- * Groups elements of an array into a record keyed by the result of `keyFn`. Each key maps to
122
- * the array of elements that produced it, in insertion order.
123
- *
124
- * Unlike `Dict.groupBy`, keys are always strings. Use `Dict.groupBy` when you need non-string
125
- * keys or want to avoid the plain-object prototype chain.
126
- *
127
- * @example
128
- * ```ts
129
- * pipe(
130
- * ["apple", "avocado", "banana", "blueberry"],
131
- * Rec.groupBy(s => s[0]),
132
- * ); // { a: ["apple", "avocado"], b: ["banana", "blueberry"] }
133
- * ```
134
- */
135
- Rec.groupBy = (keyFn) => (items) => {
136
- const result = {};
137
- for (const item of items) {
138
- const key = keyFn(item);
139
- if (key in result)
140
- result[key].push(item);
141
- else
142
- result[key] = [item];
143
- }
144
- return result;
145
- };
146
- /**
147
- * Picks specific keys from a record.
148
- *
149
- * @example
150
- * ```ts
151
- * pipe({ a: 1, b: 2, c: 3 }, Rec.pick("a", "c")); // { a: 1, c: 3 }
152
- * ```
153
- */
154
- Rec.pick = (...pickedKeys) => (data) => {
155
- const result = {};
156
- for (const key of pickedKeys) {
157
- if (Object.prototype.hasOwnProperty.call(data, key)) {
158
- result[key] = data[key];
159
- }
160
- }
161
- return result;
162
- };
163
- /**
164
- * Omits specific keys from a record.
165
- *
166
- * @example
167
- * ```ts
168
- * pipe({ a: 1, b: 2, c: 3 }, Rec.omit("b")); // { a: 1, c: 3 }
169
- * ```
170
- */
171
- Rec.omit = (...omittedKeys) => (data) => {
172
- const omitSet = new Set(omittedKeys);
173
- const result = {};
174
- for (const key of Object.keys(data)) {
175
- if (!omitSet.has(key)) {
176
- result[key] = data[key];
177
- }
178
- }
179
- return result;
180
- };
181
- /**
182
- * Merges two records. Values from the second record take precedence.
183
- *
184
- * @example
185
- * ```ts
186
- * pipe({ a: 1, b: 2 }, Rec.merge({ b: 3, c: 4 })); // { a: 1, b: 3, c: 4 }
187
- * ```
188
- */
189
- Rec.merge = (other) => (data) => ({
190
- ...data,
191
- ...other,
192
- });
193
- /**
194
- * Returns true if the record has no keys.
195
- */
196
- Rec.isEmpty = (data) => Object.keys(data).length === 0;
197
- /**
198
- * Returns the number of keys in a record.
199
- */
200
- Rec.size = (data) => Object.keys(data).length;
201
- /**
202
- * Transforms each key while preserving values.
203
- * If two keys map to the same new key, the last one wins.
204
- *
205
- * @example
206
- * ```ts
207
- * pipe({ firstName: "Alice", lastName: "Smith" }, Rec.mapKeys(k => k.toUpperCase()));
208
- * // { FIRSTNAME: "Alice", LASTNAME: "Smith" }
209
- * ```
210
- */
211
- Rec.mapKeys = (f) => (data) => {
212
- const keys = Object.keys(data);
213
- const vals = Object.values(data);
214
- const result = {};
215
- for (let i = 0; i < keys.length; i++) {
216
- result[f(keys[i])] = vals[i];
217
- }
218
- return result;
219
- };
220
- /**
221
- * Removes all `None` values from a `Record<string, Option<A>>`, returning a plain `Record<string, A>`.
222
- * Useful when building records from fallible lookups.
223
- *
224
- * @example
225
- * ```ts
226
- * Rec.compact({ a: Option.some(1), b: Option.none(), c: Option.some(3) });
227
- * // { a: 1, c: 3 }
228
- * ```
229
- */
230
- Rec.compact = (data) => {
231
- const keys = Object.keys(data);
232
- const vals = Object.values(data);
233
- const result = {};
234
- for (let i = 0; i < keys.length; i++) {
235
- const v = vals[i];
236
- if (v.kind === "Some")
237
- result[keys[i]] = v.value;
238
- }
239
- return result;
240
- };
241
- })(Rec || (Rec = {}));
@@ -1,134 +0,0 @@
1
- import { Option } from "../Core/Option.js";
2
- /**
3
- * String utilities. All transformation functions are data-last and curried so they
4
- * compose naturally with `pipe`. Safe parsers return `Option` instead of `NaN`.
5
- *
6
- * @example
7
- * ```ts
8
- * import { Str } from "@nlozgachev/pipelined/utils";
9
- * import { pipe } from "@nlozgachev/pipelined/composition";
10
- *
11
- * pipe(" Hello, World! ", Str.trim, Str.toLowerCase); // "hello, world!"
12
- * ```
13
- */
14
- export var Str;
15
- (function (Str) {
16
- /**
17
- * Splits a string by a separator. Data-last: use in `pipe`.
18
- *
19
- * @example
20
- * ```ts
21
- * pipe("a,b,c", Str.split(",")); // ["a", "b", "c"]
22
- * ```
23
- */
24
- Str.split = (separator) => (s) => s.split(separator);
25
- /**
26
- * Removes leading and trailing whitespace from a string.
27
- *
28
- * @example
29
- * ```ts
30
- * pipe(" hello ", Str.trim); // "hello"
31
- * ```
32
- */
33
- Str.trim = (s) => s.trim();
34
- /**
35
- * Returns `true` when the string contains the given substring.
36
- *
37
- * @example
38
- * ```ts
39
- * pipe("hello world", Str.includes("world")); // true
40
- * pipe("hello world", Str.includes("xyz")); // false
41
- * ```
42
- */
43
- Str.includes = (substring) => (s) => s.includes(substring);
44
- /**
45
- * Returns `true` when the string starts with the given prefix.
46
- *
47
- * @example
48
- * ```ts
49
- * pipe("hello world", Str.startsWith("hello")); // true
50
- * pipe("hello world", Str.startsWith("world")); // false
51
- * ```
52
- */
53
- Str.startsWith = (prefix) => (s) => s.startsWith(prefix);
54
- /**
55
- * Returns `true` when the string ends with the given suffix.
56
- *
57
- * @example
58
- * ```ts
59
- * pipe("hello world", Str.endsWith("world")); // true
60
- * pipe("hello world", Str.endsWith("hello")); // false
61
- * ```
62
- */
63
- Str.endsWith = (suffix) => (s) => s.endsWith(suffix);
64
- /**
65
- * Converts a string to uppercase.
66
- *
67
- * @example
68
- * ```ts
69
- * pipe("hello", Str.toUpperCase); // "HELLO"
70
- * ```
71
- */
72
- Str.toUpperCase = (s) => s.toUpperCase();
73
- /**
74
- * Converts a string to lowercase.
75
- *
76
- * @example
77
- * ```ts
78
- * pipe("HELLO", Str.toLowerCase); // "hello"
79
- * ```
80
- */
81
- Str.toLowerCase = (s) => s.toLowerCase();
82
- /**
83
- * Splits a string into lines, normalising `\r\n` and `\r` line endings.
84
- *
85
- * @example
86
- * ```ts
87
- * Str.lines("one\ntwo\nthree"); // ["one", "two", "three"]
88
- * Str.lines("a\r\nb"); // ["a", "b"]
89
- * ```
90
- */
91
- Str.lines = (s) => s.split(/\r?\n|\r/);
92
- /**
93
- * Splits a string into words on any whitespace boundary, filtering out empty strings.
94
- *
95
- * @example
96
- * ```ts
97
- * Str.words(" hello world "); // ["hello", "world"]
98
- * ```
99
- */
100
- Str.words = (s) => s.trim().split(/\s+/).filter(Boolean);
101
- /**
102
- * Safe number parsers that return `Option` instead of `NaN`.
103
- */
104
- Str.parse = {
105
- /**
106
- * Parses a string as an integer (base 10). Returns `None` if the result is `NaN`.
107
- *
108
- * @example
109
- * ```ts
110
- * Str.parse.int("42"); // Some(42)
111
- * Str.parse.int("3.7"); // Some(3)
112
- * Str.parse.int("abc"); // None
113
- * ```
114
- */
115
- int: (s) => {
116
- const n = parseInt(s, 10);
117
- return isNaN(n) ? Option.none() : Option.some(n);
118
- },
119
- /**
120
- * Parses a string as a floating-point number. Returns `None` if the result is `NaN`.
121
- *
122
- * @example
123
- * ```ts
124
- * Str.parse.float("3.14"); // Some(3.14)
125
- * Str.parse.float("42"); // Some(42)
126
- * Str.parse.float("abc"); // None
127
- * ```
128
- */
129
- float: (s) => {
130
- const n = parseFloat(s);
131
- return isNaN(n) ? Option.none() : Option.some(n);
132
- },
133
- };
134
- })(Str || (Str = {}));
@@ -1,265 +0,0 @@
1
- /**
2
- * Functional utilities for unique-value collections (`ReadonlySet<A>`). All functions are pure
3
- * and data-last — they compose naturally with `pipe`.
4
- *
5
- * Every "mutating" operation returns a new set; the original is never changed.
6
- *
7
- * @example
8
- * ```ts
9
- * import { Uniq } from "@nlozgachev/pipelined/utils";
10
- * import { pipe } from "@nlozgachev/pipelined/composition";
11
- *
12
- * const active = pipe(
13
- * Uniq.fromArray(["alice", "bob", "alice", "carol"]),
14
- * Uniq.remove("bob"),
15
- * Uniq.map(name => name.toUpperCase()),
16
- * );
17
- * // ReadonlySet { "ALICE", "CAROL" }
18
- * ```
19
- */
20
- export var Uniq;
21
- (function (Uniq) {
22
- // ---------------------------------------------------------------------------
23
- // Constructors
24
- // ---------------------------------------------------------------------------
25
- /**
26
- * Creates an empty unique collection.
27
- *
28
- * @example
29
- * ```ts
30
- * Uniq.empty<number>(); // ReadonlySet {}
31
- * ```
32
- */
33
- Uniq.empty = () => new globalThis.Set();
34
- /**
35
- * Creates a unique collection containing a single item.
36
- *
37
- * @example
38
- * ```ts
39
- * Uniq.singleton(42); // ReadonlySet { 42 }
40
- * ```
41
- */
42
- Uniq.singleton = (item) => new globalThis.Set([item]);
43
- /**
44
- * Creates a unique collection from an array, automatically discarding duplicates.
45
- *
46
- * @example
47
- * ```ts
48
- * Uniq.fromArray([1, 2, 2, 3, 3, 3]); // ReadonlySet { 1, 2, 3 }
49
- * Uniq.fromArray([]); // ReadonlySet {}
50
- * ```
51
- */
52
- Uniq.fromArray = (arr) => new globalThis.Set(arr);
53
- // ---------------------------------------------------------------------------
54
- // Query
55
- // ---------------------------------------------------------------------------
56
- /**
57
- * Returns `true` if the collection contains the given item.
58
- *
59
- * @example
60
- * ```ts
61
- * pipe(Uniq.fromArray([1, 2, 3]), Uniq.has(2)); // true
62
- * pipe(Uniq.fromArray([1, 2, 3]), Uniq.has(4)); // false
63
- * ```
64
- */
65
- Uniq.has = (item) => (s) => s.has(item);
66
- /**
67
- * Returns the number of items in the collection.
68
- *
69
- * @example
70
- * ```ts
71
- * Uniq.size(Uniq.fromArray([1, 2, 3])); // 3
72
- * ```
73
- */
74
- Uniq.size = (s) => s.size;
75
- /**
76
- * Returns `true` if the collection has no items.
77
- *
78
- * @example
79
- * ```ts
80
- * Uniq.isEmpty(Uniq.empty()); // true
81
- * ```
82
- */
83
- Uniq.isEmpty = (s) => s.size === 0;
84
- /**
85
- * Returns `true` if every item in `set` also exists in `other`.
86
- *
87
- * @example
88
- * ```ts
89
- * pipe(Uniq.fromArray([1, 2]), Uniq.isSubsetOf(Uniq.fromArray([1, 2, 3]))); // true
90
- * pipe(Uniq.fromArray([1, 4]), Uniq.isSubsetOf(Uniq.fromArray([1, 2, 3]))); // false
91
- * pipe(Uniq.empty<number>(), Uniq.isSubsetOf(Uniq.fromArray([1, 2, 3]))); // true
92
- * ```
93
- */
94
- Uniq.isSubsetOf = (other) => (s) => {
95
- const set = s;
96
- if (typeof set.isSubsetOf === "function")
97
- return set.isSubsetOf(other);
98
- for (const item of s)
99
- if (!other.has(item))
100
- return false;
101
- return true;
102
- };
103
- // ---------------------------------------------------------------------------
104
- // Modification
105
- // ---------------------------------------------------------------------------
106
- /**
107
- * Returns a new collection with the item added. If the item is already present, returns the
108
- * original collection unchanged.
109
- *
110
- * @example
111
- * ```ts
112
- * pipe(Uniq.fromArray([1, 2]), Uniq.insert(3)); // ReadonlySet { 1, 2, 3 }
113
- * pipe(Uniq.fromArray([1, 2]), Uniq.insert(2)); // ReadonlySet { 1, 2 } — unchanged
114
- * ```
115
- */
116
- Uniq.insert = (item) => (s) => {
117
- if (s.has(item))
118
- return s;
119
- const result = new globalThis.Set(s);
120
- result.add(item);
121
- return result;
122
- };
123
- /**
124
- * Returns a new collection with the item removed. If the item is not present, returns the
125
- * original collection unchanged.
126
- *
127
- * @example
128
- * ```ts
129
- * pipe(Uniq.fromArray([1, 2, 3]), Uniq.remove(2)); // ReadonlySet { 1, 3 }
130
- * pipe(Uniq.fromArray([1, 2, 3]), Uniq.remove(4)); // ReadonlySet { 1, 2, 3 } — unchanged
131
- * ```
132
- */
133
- Uniq.remove = (item) => (s) => {
134
- if (!s.has(item))
135
- return s;
136
- const result = new globalThis.Set(s);
137
- result.delete(item);
138
- return result;
139
- };
140
- // ---------------------------------------------------------------------------
141
- // Transform
142
- // ---------------------------------------------------------------------------
143
- /**
144
- * Applies `f` to each item, returning a new collection of the results. Duplicate results are
145
- * automatically merged.
146
- *
147
- * @example
148
- * ```ts
149
- * pipe(Uniq.fromArray([1, 2, 3, 4]), Uniq.map(n => n % 3)); // ReadonlySet { 1, 2, 0 }
150
- * ```
151
- */
152
- Uniq.map = (f) => (s) => {
153
- const result = new globalThis.Set();
154
- for (const item of s) {
155
- result.add(f(item));
156
- }
157
- return result;
158
- };
159
- /**
160
- * Returns a new collection containing only the items for which the predicate returns `true`.
161
- *
162
- * @example
163
- * ```ts
164
- * pipe(Uniq.fromArray([1, 2, 3, 4, 5]), Uniq.filter(n => n % 2 === 0));
165
- * // ReadonlySet { 2, 4 }
166
- * ```
167
- */
168
- Uniq.filter = (predicate) => (s) => {
169
- const result = new globalThis.Set();
170
- for (const item of s) {
171
- if (predicate(item))
172
- result.add(item);
173
- }
174
- return result;
175
- };
176
- // ---------------------------------------------------------------------------
177
- // Set operations
178
- // ---------------------------------------------------------------------------
179
- /**
180
- * Returns a new collection containing all items from both collections.
181
- *
182
- * @example
183
- * ```ts
184
- * pipe(Uniq.fromArray([1, 2, 3]), Uniq.union(Uniq.fromArray([2, 3, 4])));
185
- * // ReadonlySet { 1, 2, 3, 4 }
186
- * ```
187
- */
188
- Uniq.union = (other) => (s) => {
189
- const set = s;
190
- if (typeof set.union === "function")
191
- return set.union(other);
192
- const result = new globalThis.Set(s);
193
- for (const item of other)
194
- result.add(item);
195
- return result;
196
- };
197
- /**
198
- * Returns a new collection containing only the items that appear in both collections.
199
- *
200
- * @example
201
- * ```ts
202
- * pipe(Uniq.fromArray([1, 2, 3]), Uniq.intersection(Uniq.fromArray([2, 3, 4])));
203
- * // ReadonlySet { 2, 3 }
204
- * ```
205
- */
206
- Uniq.intersection = (other) => (s) => {
207
- const set = s;
208
- if (typeof set.intersection === "function")
209
- return set.intersection(other);
210
- const result = new globalThis.Set();
211
- for (const item of s)
212
- if (other.has(item))
213
- result.add(item);
214
- return result;
215
- };
216
- /**
217
- * Returns a new collection containing only the items from `set` that do not appear in `other`.
218
- *
219
- * @example
220
- * ```ts
221
- * pipe(Uniq.fromArray([1, 2, 3, 4]), Uniq.difference(Uniq.fromArray([2, 4])));
222
- * // ReadonlySet { 1, 3 }
223
- * ```
224
- */
225
- Uniq.difference = (other) => (s) => {
226
- const set = s;
227
- if (typeof set.difference === "function")
228
- return set.difference(other);
229
- const result = new globalThis.Set();
230
- for (const item of s)
231
- if (!other.has(item))
232
- result.add(item);
233
- return result;
234
- };
235
- // ---------------------------------------------------------------------------
236
- // Fold
237
- // ---------------------------------------------------------------------------
238
- /**
239
- * Folds the collection into a single value by applying `f` to each item in insertion order.
240
- *
241
- * @example
242
- * ```ts
243
- * Uniq.reduce(0, (acc, n) => acc + n)(Uniq.fromArray([1, 2, 3])); // 6
244
- * ```
245
- */
246
- Uniq.reduce = (init, f) => (s) => {
247
- let acc = init;
248
- for (const item of s) {
249
- acc = f(acc, item);
250
- }
251
- return acc;
252
- };
253
- // ---------------------------------------------------------------------------
254
- // Convert
255
- // ---------------------------------------------------------------------------
256
- /**
257
- * Converts the collection to a readonly array in insertion order.
258
- *
259
- * @example
260
- * ```ts
261
- * Uniq.toArray(Uniq.fromArray([3, 1, 2])); // [3, 1, 2]
262
- * ```
263
- */
264
- Uniq.toArray = (s) => [...s];
265
- })(Uniq || (Uniq = {}));
@@ -1,6 +0,0 @@
1
- export * from "./Arr.js";
2
- export * from "./Rec.js";
3
- export * from "./Num.js";
4
- export * from "./Str.js";
5
- export * from "./Dict.js";
6
- export * from "./Uniq.js";
package/script/mod.js DELETED
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./src/Composition/index.js"), exports);
18
- __exportStar(require("./src/Core/index.js"), exports);
19
- __exportStar(require("./src/Composition/index.js"), exports);
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.compose = compose;
4
- function compose(...fns) {
5
- return (arg) => fns.reduceRight((acc, fn) => fn(acc), arg);
6
- }
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.converge = converge;
4
- function converge(f, transformers) {
5
- return (a) => f(...transformers.map((t) => t(a)));
6
- }