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