@nlozgachev/pipelined 0.58.0 → 0.59.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.
package/README.md CHANGED
@@ -555,12 +555,12 @@ if (Result.is.ok(email)) {
555
555
  - **`@nlozgachev/pipelined/core`**: Core context containers, async runtimes, optics, and logic
556
556
  abstractions (<16 KB gzipped).
557
557
  - **`@nlozgachev/pipelined/data`**: Curried, data-last utilities for collections, numbers, strings,
558
- and JSON (<13 KB gzipped).
558
+ and JSON (<10 KB gzipped).
559
559
  - **`@nlozgachev/pipelined/composition`**: Pure higher-order function combinators (`pipe`, `flow`,
560
560
  `compose`, `curry`, `uncurry`, `converge`, `juxt`, `memoize`, `tap`, `on`, `not`, `flip`, `fn`)
561
- (<4 KB gzipped).
562
- - **`@nlozgachev/pipelined/types`**: Type-level utilities (`Brand`, `Duration`, `RetryPolicy`) (<2
563
- KB gzipped).
561
+ (<3 KB gzipped).
562
+ - **`@nlozgachev/pipelined/types`**: Type-level utilities (`Brand`, `Duration`, `RetryPolicy`) (<700
563
+ B gzipped).
564
564
 
565
565
  Every utility in the library is benchmarked against its native equivalent. While currying introduces
566
566
  a small function call overhead for composability, the library uses custom algorithms for
@@ -1,7 +1,3 @@
1
- import {
2
- Duration
3
- } from "./chunk-OIIOGDHK.js";
4
-
5
1
  // src/Composition/compose.ts
6
2
  function compose(f0, f1, f2, f3, f4, f5, f6, f7, f8, f9) {
7
3
  const len = arguments.length;
@@ -324,6 +320,36 @@ pipe.try = (f, onError) => (a) => {
324
320
 
325
321
  // src/Composition/tap.ts
326
322
  import { inspect as nodeInspect } from "util";
323
+
324
+ // src/Types/Brand.ts
325
+ var Brand;
326
+ ((Brand2) => {
327
+ Brand2.wrap = () => (value) => value;
328
+ Brand2.unwrap = (branded) => branded;
329
+ })(Brand || (Brand = {}));
330
+
331
+ // src/Types/Duration.ts
332
+ var Duration;
333
+ ((Duration2) => {
334
+ const wrap = Brand.wrap();
335
+ Duration2.milliseconds = (ms) => wrap(ms);
336
+ Duration2.seconds = (s) => wrap(s * 1e3);
337
+ Duration2.minutes = (m) => wrap(m * 60 * 1e3);
338
+ Duration2.hours = (h) => wrap(h * 60 * 60 * 1e3);
339
+ Duration2.days = (d) => wrap(d * 24 * 60 * 60 * 1e3);
340
+ let to;
341
+ ((to2) => {
342
+ to2.milliseconds = (d) => Brand.unwrap(d);
343
+ to2.seconds = (d) => Brand.unwrap(d) / 1e3;
344
+ to2.minutes = (d) => Brand.unwrap(d) / (60 * 1e3);
345
+ to2.hours = (d) => Brand.unwrap(d) / (60 * 60 * 1e3);
346
+ to2.days = (d) => Brand.unwrap(d) / (24 * 60 * 60 * 1e3);
347
+ })(to = Duration2.to || (Duration2.to = {}));
348
+ Duration2.add = (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other));
349
+ Duration2.subtract = (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other));
350
+ })(Duration || (Duration = {}));
351
+
352
+ // src/Composition/tap.ts
327
353
  function tap(f) {
328
354
  return (a) => {
329
355
  f(a);
@@ -417,36 +443,35 @@ function uncurry(f) {
417
443
  }
418
444
  var uncurry3 = (f) => (a, b, c) => f(a)(b)(c);
419
445
  var uncurry4 = (f) => (a, b, c, d) => f(a)(b)(c)(d);
420
-
421
446
  export {
447
+ and,
422
448
  compose,
449
+ constFalse,
450
+ constNull,
451
+ constTrue,
452
+ constUndefined,
453
+ constVoid,
454
+ constant,
423
455
  converge,
424
456
  curry,
425
457
  curry3,
426
458
  curry4,
459
+ defaultTo,
427
460
  flip,
428
461
  flow,
429
462
  identity,
430
- constant,
431
- constTrue,
432
- constFalse,
433
- constNull,
434
- constUndefined,
435
- constVoid,
436
- and,
437
- or,
438
- once,
439
- defaultTo,
440
- tuple,
441
- untuple,
442
463
  juxt,
443
464
  memoize,
444
465
  memoizeWeak,
445
466
  not,
446
467
  on,
468
+ once,
469
+ or,
447
470
  pipe,
448
471
  tap,
472
+ tuple,
449
473
  uncurry,
450
474
  uncurry3,
451
- uncurry4
475
+ uncurry4,
476
+ untuple
452
477
  };
@@ -1,7 +1,3 @@
1
- import {
2
- Duration
3
- } from "./chunk-OIIOGDHK.js";
4
-
5
1
  // src/Core/Combinable.ts
6
2
  var Combinable;
7
3
  ((Combinable2) => {
@@ -232,6 +228,34 @@ var Maybe;
232
228
  Maybe3.transposeResult = (data) => is.none(data) ? Result.make.ok(make.none()) : Result.is.ok(data.value) ? Result.make.ok(make.some(data.value.value)) : Result.make.err(data.value.error);
233
229
  })(Maybe || (Maybe = {}));
234
230
 
231
+ // src/Types/Brand.ts
232
+ var Brand;
233
+ ((Brand2) => {
234
+ Brand2.wrap = () => (value) => value;
235
+ Brand2.unwrap = (branded) => branded;
236
+ })(Brand || (Brand = {}));
237
+
238
+ // src/Types/Duration.ts
239
+ var Duration;
240
+ ((Duration2) => {
241
+ const wrap = Brand.wrap();
242
+ Duration2.milliseconds = (ms) => wrap(ms);
243
+ Duration2.seconds = (s) => wrap(s * 1e3);
244
+ Duration2.minutes = (m) => wrap(m * 60 * 1e3);
245
+ Duration2.hours = (h) => wrap(h * 60 * 60 * 1e3);
246
+ Duration2.days = (d) => wrap(d * 24 * 60 * 60 * 1e3);
247
+ let to;
248
+ ((to2) => {
249
+ to2.milliseconds = (d) => Brand.unwrap(d);
250
+ to2.seconds = (d) => Brand.unwrap(d) / 1e3;
251
+ to2.minutes = (d) => Brand.unwrap(d) / (60 * 1e3);
252
+ to2.hours = (d) => Brand.unwrap(d) / (60 * 60 * 1e3);
253
+ to2.days = (d) => Brand.unwrap(d) / (24 * 60 * 60 * 1e3);
254
+ })(to = Duration2.to || (Duration2.to = {}));
255
+ Duration2.add = (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other));
256
+ Duration2.subtract = (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other));
257
+ })(Duration || (Duration = {}));
258
+
235
259
  // src/internal/Op.util.ts
236
260
  var _abortedNil = { kind: "OpNil", reason: "aborted" };
237
261
  var _droppedNil = { kind: "OpNil", reason: "dropped" };
@@ -2593,7 +2617,6 @@ var Validation;
2593
2617
  return isNonEmptyArr(errors) ? make.failedAll(errors) : make.passed(record);
2594
2618
  };
2595
2619
  })(Validation || (Validation = {}));
2596
-
2597
2620
  export {
2598
2621
  Combinable,
2599
2622
  Deferred,
@@ -2614,7 +2637,6 @@ export {
2614
2637
  Result,
2615
2638
  State,
2616
2639
  Stream,
2617
- isNonEmptyArr,
2618
2640
  Task,
2619
2641
  These,
2620
2642
  Validation
@@ -1,9 +1,264 @@
1
- import {
2
- Deferred,
3
- Maybe,
4
- Result,
5
- isNonEmptyArr
6
- } from "./chunk-VYHAA4KO.js";
1
+ // src/Core/Deferred.ts
2
+ var Deferred;
3
+ ((Deferred2) => {
4
+ let from;
5
+ ((from2) => {
6
+ from2.Promise = (p) => (
7
+ // eslint-disable-next-line unicorn/no-thenable -- Deferred is intentionally thenable; it is the mechanism that makes Task awaitable
8
+ { then: ((f) => p.then(f)) }
9
+ );
10
+ })(from = Deferred2.from || (Deferred2.from = {}));
11
+ let to;
12
+ ((to2) => {
13
+ to2.Promise = (d) => new globalThis.Promise((resolve) => d.then(resolve));
14
+ })(to = Deferred2.to || (Deferred2.to = {}));
15
+ Deferred2.all = (deferreds) => from.Promise(globalThis.Promise.all(deferreds.map((d) => to.Promise(d))));
16
+ Deferred2.race = (deferreds) => from.Promise(globalThis.Promise.race(deferreds.map((d) => to.Promise(d))));
17
+ })(Deferred || (Deferred = {}));
18
+
19
+ // src/Core/Maybe.ts
20
+ var _none = { kind: "None" };
21
+ var Maybe;
22
+ ((Maybe2) => {
23
+ let make;
24
+ ((make2) => {
25
+ make2.some = (value) => ({ kind: "Some", value });
26
+ make2.none = () => _none;
27
+ })(make = Maybe2.make || (Maybe2.make = {}));
28
+ let is;
29
+ ((is2) => {
30
+ is2.some = (data) => data.kind === "Some";
31
+ is2.none = (data) => data.kind === "None";
32
+ })(is = Maybe2.is || (Maybe2.is = {}));
33
+ let to;
34
+ ((to2) => {
35
+ to2.nullable = (data) => is.some(data) ? data.value : null;
36
+ to2.undefined = (data) => is.some(data) ? data.value : globalThis.undefined;
37
+ to2.Result = (onNone) => (data) => is.some(data) ? Result.make.ok(data.value) : Result.make.err(onNone());
38
+ })(to = Maybe2.to || (Maybe2.to = {}));
39
+ let from;
40
+ ((from2) => {
41
+ from2.nullable = (value) => value === null || value === void 0 ? make.none() : make.some(value);
42
+ from2.Predicate = (pred) => (a) => pred(a) ? make.some(a) : make.none();
43
+ from2.Result = (data) => Result.is.ok(data) ? make.some(data.value) : make.none();
44
+ })(from = Maybe2.from || (Maybe2.from = {}));
45
+ Maybe2.map = (f) => (data) => is.some(data) ? make.some(f(data.value)) : data;
46
+ Maybe2.chain = (f) => (data) => is.some(data) ? f(data.value) : data;
47
+ Maybe2.fold = (onNone, onSome) => (data) => is.some(data) ? onSome(data.value) : onNone();
48
+ Maybe2.match = (cases) => (data) => is.some(data) ? cases.some(data.value) : cases.none();
49
+ Maybe2.getOrElse = (defaultValue) => (data) => is.some(data) ? data.value : defaultValue();
50
+ Maybe2.tap = (f) => (data) => {
51
+ if (is.some(data)) {
52
+ f(data.value);
53
+ }
54
+ return data;
55
+ };
56
+ Maybe2.filter = (predicate) => (data) => is.some(data) ? predicate(data.value) ? data : make.none() : data;
57
+ Maybe2.recover = (fallback) => (data) => is.some(data) ? data : fallback();
58
+ Maybe2.ap = (arg) => (data) => is.some(data) && is.some(arg) ? make.some(data.value(arg.value)) : make.none();
59
+ Maybe2.bindTo = (key) => (data) => (0, Maybe2.map)((a) => ({ [key]: a }))(data);
60
+ Maybe2.bind = (key, f) => (data) => (0, Maybe2.chain)(
61
+ (a) => (0, Maybe2.map)((b) => ({ ...a, [key]: b }))(f(a))
62
+ )(data);
63
+ Maybe2.struct = (fields) => {
64
+ const result = {};
65
+ for (const key in fields) {
66
+ if (Object.hasOwn(fields, key)) {
67
+ const res = fields[key];
68
+ if (is.none(res)) {
69
+ return res;
70
+ }
71
+ result[key] = res.value;
72
+ }
73
+ }
74
+ return make.some(result);
75
+ };
76
+ Maybe2.transposeResult = (data) => is.none(data) ? Result.make.ok(make.none()) : Result.is.ok(data.value) ? Result.make.ok(make.some(data.value.value)) : Result.make.err(data.value.error);
77
+ })(Maybe || (Maybe = {}));
78
+
79
+ // src/Core/Result.ts
80
+ var Result;
81
+ ((Result2) => {
82
+ let make;
83
+ ((make2) => {
84
+ make2.ok = (value) => ({ kind: "Ok", value });
85
+ make2.err = (e) => ({ kind: "Err", error: e });
86
+ })(make = Result2.make || (Result2.make = {}));
87
+ let is;
88
+ ((is2) => {
89
+ is2.ok = (data) => data.kind === "Ok";
90
+ is2.err = (data) => data.kind === "Err";
91
+ })(is = Result2.is || (Result2.is = {}));
92
+ Result2.tryCatch = (f, options) => {
93
+ try {
94
+ return make.ok(f());
95
+ } catch (error) {
96
+ return make.err(options.onError(error));
97
+ }
98
+ };
99
+ Result2.map = (f) => (data) => is.ok(data) ? make.ok(f(data.value)) : data;
100
+ Result2.mapError = (f) => (data) => is.err(data) ? make.err(f(data.error)) : data;
101
+ Result2.chain = (f) => (data) => is.ok(data) ? f(data.value) : data;
102
+ Result2.fold = (onErr, onOk) => (data) => is.ok(data) ? onOk(data.value) : onErr(data.error);
103
+ Result2.match = (cases) => (data) => is.ok(data) ? cases.ok(data.value) : cases.err(data.error);
104
+ Result2.getOrElse = (defaultValue) => (data) => is.ok(data) ? data.value : defaultValue();
105
+ Result2.tap = (f) => (data) => {
106
+ if (is.ok(data)) {
107
+ f(data.value);
108
+ }
109
+ return data;
110
+ };
111
+ Result2.tapError = (f) => (data) => {
112
+ if (is.err(data)) {
113
+ f(data.error);
114
+ }
115
+ return data;
116
+ };
117
+ let from;
118
+ ((from2) => {
119
+ from2.Predicate = (pred, onFalse) => (a) => pred(a) ? make.ok(a) : make.err(onFalse(a));
120
+ from2.nullable = (onNull) => (value) => value === null || value === void 0 ? make.err(onNull()) : make.ok(value);
121
+ from2.Maybe = (onNone) => (maybe) => Maybe.is.none(maybe) ? make.err(onNone()) : make.ok(maybe.value);
122
+ from2.Validation = (combineErrors) => (val) => Validation.is.passed(val) ? make.ok(val.value) : make.err(combineErrors(val.errors));
123
+ })(from = Result2.from || (Result2.from = {}));
124
+ Result2.recover = (fallback) => (data) => is.ok(data) ? data : fallback(data.error);
125
+ Result2.recoverUnless = (isBlocked, fallback) => (data) => is.err(data) && !isBlocked(data.error) ? fallback() : data;
126
+ let to;
127
+ ((to2) => {
128
+ to2.Maybe = (data) => is.ok(data) ? Maybe.make.some(data.value) : Maybe.make.none();
129
+ to2.Validation = (data) => Validation.from.Result(data);
130
+ })(to = Result2.to || (Result2.to = {}));
131
+ Result2.transposeMaybe = (data) => is.err(data) ? Maybe.make.some(data) : Maybe.is.some(data.value) ? Maybe.make.some(make.ok(data.value.value)) : Maybe.make.none();
132
+ Result2.ap = (arg) => (data) => is.ok(data) && is.ok(arg) ? make.ok(data.value(arg.value)) : is.err(data) ? data : arg;
133
+ Result2.bindTo = (key) => (data) => (0, Result2.map)((a) => ({ [key]: a }))(data);
134
+ Result2.bind = (key, f) => (data) => (0, Result2.chain)(
135
+ (a) => (0, Result2.map)((b) => ({ ...a, [key]: b }))(f(a))
136
+ )(data);
137
+ Result2.struct = (fields) => {
138
+ const result = {};
139
+ for (const key in fields) {
140
+ if (Object.hasOwn(fields, key)) {
141
+ const res = fields[key];
142
+ if (is.err(res)) {
143
+ return res;
144
+ }
145
+ result[key] = res.value;
146
+ }
147
+ }
148
+ return make.ok(result);
149
+ };
150
+ Result2.ensure = (predicate, onFail) => (data) => is.err(data) ? data : predicate(data.value) ? data : make.err(onFail(data.value));
151
+ Result2.bimap = (onErr, onOk) => (data) => is.ok(data) ? make.ok(onOk(data.value)) : make.err(onErr(data.error));
152
+ })(Result || (Result = {}));
153
+
154
+ // src/internal/InternalTypes.ts
155
+ var isNonEmptyArr = (list) => list.length > 0;
156
+
157
+ // src/Core/Validation.ts
158
+ var Validation;
159
+ ((Validation2) => {
160
+ let make;
161
+ ((make2) => {
162
+ make2.passed = (value) => ({ kind: "Passed", value });
163
+ make2.failed = (error) => ({ kind: "Failed", errors: [error] });
164
+ make2.failedAll = (errors) => ({ kind: "Failed", errors });
165
+ })(make = Validation2.make || (Validation2.make = {}));
166
+ let is;
167
+ ((is2) => {
168
+ is2.passed = (data) => data.kind === "Passed";
169
+ is2.failed = (data) => data.kind === "Failed";
170
+ })(is = Validation2.is || (Validation2.is = {}));
171
+ Validation2.tryCatch = (f, options) => {
172
+ try {
173
+ return make.passed(f());
174
+ } catch (error) {
175
+ return make.failed(options.onError(error));
176
+ }
177
+ };
178
+ let from;
179
+ ((from2) => {
180
+ from2.Predicate = (pred, onFalse) => (a) => pred(a) ? make.passed(a) : make.failed(onFalse(a));
181
+ from2.nullable = (onNull) => (value) => value === null || value === void 0 ? make.failed(onNull()) : make.passed(value);
182
+ from2.Maybe = (onNone) => (maybe) => Maybe.is.none(maybe) ? make.failed(onNone()) : make.passed(maybe.value);
183
+ from2.Result = (data) => data.kind === "Ok" ? make.passed(data.value) : make.failed(data.error);
184
+ })(from = Validation2.from || (Validation2.from = {}));
185
+ Validation2.map = (f) => (data) => is.passed(data) ? make.passed(f(data.value)) : data;
186
+ Validation2.mapError = (f) => (data) => is.failed(data) ? make.failedAll(data.errors.map(f)) : data;
187
+ Validation2.ap = (arg) => (data) => {
188
+ if (is.passed(data)) {
189
+ return is.passed(arg) ? make.passed(data.value(arg.value)) : make.failedAll(arg.errors);
190
+ }
191
+ return is.passed(arg) ? make.failedAll(data.errors) : make.failedAll([...data.errors, ...arg.errors]);
192
+ };
193
+ Validation2.apCustom = (concat) => (arg) => (data) => {
194
+ if (is.passed(data)) {
195
+ return is.passed(arg) ? make.passed(data.value(arg.value)) : make.failedAll(arg.errors);
196
+ }
197
+ return is.passed(arg) ? make.failedAll(data.errors) : make.failedAll(concat(data.errors, arg.errors));
198
+ };
199
+ Validation2.fold = (onFailed, onPassed) => (data) => is.passed(data) ? onPassed(data.value) : onFailed(data.errors);
200
+ Validation2.match = (cases) => (data) => is.passed(data) ? cases.passed(data.value) : cases.failed(data.errors);
201
+ Validation2.getOrElse = (defaultValue) => (data) => is.passed(data) ? data.value : defaultValue();
202
+ Validation2.tap = (f) => (data) => {
203
+ if (is.passed(data)) {
204
+ f(data.value);
205
+ }
206
+ return data;
207
+ };
208
+ Validation2.tapError = (f) => (data) => {
209
+ if (is.failed(data)) {
210
+ f(data.errors);
211
+ }
212
+ return data;
213
+ };
214
+ Validation2.recover = (fallback) => (data) => is.passed(data) ? data : fallback(data.errors);
215
+ Validation2.recoverUnless = (isBlocked, fallback) => (data) => is.failed(data) && !data.errors.some(isBlocked) ? fallback() : data;
216
+ let to;
217
+ ((to2) => {
218
+ function Result2(arg) {
219
+ if (typeof arg === "function") {
220
+ const combine = arg;
221
+ return (val) => is.passed(val) ? Result.make.ok(val.value) : Result.make.err(combine(val.errors));
222
+ }
223
+ return is.passed(arg) ? Result.make.ok(arg.value) : Result.make.err(arg.errors);
224
+ }
225
+ to2.Result = Result2;
226
+ to2.Maybe = (data) => is.passed(data) ? Maybe.make.some(data.value) : Maybe.make.none();
227
+ })(to = Validation2.to || (Validation2.to = {}));
228
+ Validation2.product = (first, second) => {
229
+ if (is.passed(first)) {
230
+ return is.passed(second) ? make.passed([first.value, second.value]) : make.failedAll(second.errors);
231
+ }
232
+ return is.passed(second) ? make.failedAll(first.errors) : make.failedAll([...first.errors, ...second.errors]);
233
+ };
234
+ Validation2.productAll = (data) => {
235
+ const values = [];
236
+ const errors = [];
237
+ for (const v of data) {
238
+ if (is.passed(v)) {
239
+ values.push(v.value);
240
+ } else {
241
+ errors.push(...v.errors);
242
+ }
243
+ }
244
+ return isNonEmptyArr(errors) ? make.failedAll(errors) : make.passed(values);
245
+ };
246
+ Validation2.struct = (fields) => {
247
+ const record = {};
248
+ const errors = [];
249
+ for (const key in fields) {
250
+ if (Object.hasOwn(fields, key)) {
251
+ const val = fields[key];
252
+ if (is.passed(val)) {
253
+ record[key] = val.value;
254
+ } else {
255
+ errors.push(...val.errors);
256
+ }
257
+ }
258
+ }
259
+ return isNonEmptyArr(errors) ? make.failedAll(errors) : make.passed(record);
260
+ };
261
+ })(Validation || (Validation = {}));
7
262
 
8
263
  // src/Data/Arr.ts
9
264
  var ArrMaybe;
@@ -1311,7 +1566,6 @@ var Uniq;
1311
1566
  })(to = Uniq2.to || (Uniq2.to = {}));
1312
1567
  Uniq2.NonEmpty = UniqNonEmpty;
1313
1568
  })(Uniq || (Uniq = {}));
1314
-
1315
1569
  export {
1316
1570
  Arr,
1317
1571
  BigNum,