@nlozgachev/pipelined 0.64.0 → 0.65.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.
@@ -1,666 +1,758 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/Composition/index.ts
21
- var Composition_exports = {};
22
- __export(Composition_exports, {
23
- and: () => and,
24
- compose: () => compose,
25
- constFalse: () => constFalse,
26
- constNull: () => constNull,
27
- constTrue: () => constTrue,
28
- constUndefined: () => constUndefined,
29
- constVoid: () => constVoid,
30
- constant: () => constant,
31
- converge: () => converge,
32
- curry: () => curry,
33
- curry3: () => curry3,
34
- curry4: () => curry4,
35
- defaultTo: () => defaultTo,
36
- flip: () => flip,
37
- flow: () => flow,
38
- identity: () => identity,
39
- juxt: () => juxt,
40
- memoize: () => memoize,
41
- memoizeWeak: () => memoizeWeak,
42
- not: () => not,
43
- on: () => on,
44
- once: () => once,
45
- or: () => or,
46
- pipe: () => pipe,
47
- tap: () => tap,
48
- tuple: () => tuple,
49
- uncurry: () => uncurry,
50
- uncurry3: () => uncurry3,
51
- uncurry4: () => uncurry4,
52
- untuple: () => untuple
53
- });
54
- module.exports = __toCommonJS(Composition_exports);
55
-
56
- // src/Composition/compose.ts
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_types = require("./types.cjs");
3
+ let node_util = require("node:util");
4
+ //#region src/Composition/compose.ts
57
5
  function compose(f0, f1, f2, f3, f4, f5, f6, f7, f8, f9) {
58
- const len = arguments.length;
59
- switch (len) {
60
- case 1: {
61
- return f0;
62
- }
63
- case 2: {
64
- return function() {
65
- return f0(f1.apply(this, arguments));
66
- };
67
- }
68
- case 3: {
69
- return function() {
70
- return f0(f1(f2.apply(this, arguments)));
71
- };
72
- }
73
- case 4: {
74
- return function() {
75
- return f0(f1(f2(f3.apply(this, arguments))));
76
- };
77
- }
78
- case 5: {
79
- return function() {
80
- return f0(f1(f2(f3(f4.apply(this, arguments)))));
81
- };
82
- }
83
- case 6: {
84
- return function() {
85
- return f0(f1(f2(f3(f4(f5.apply(this, arguments))))));
86
- };
87
- }
88
- case 7: {
89
- return function() {
90
- return f0(f1(f2(f3(f4(f5(f6.apply(this, arguments)))))));
91
- };
92
- }
93
- case 8: {
94
- return function() {
95
- return f0(f1(f2(f3(f4(f5(f6(f7.apply(this, arguments))))))));
96
- };
97
- }
98
- case 9: {
99
- return function() {
100
- return f0(f1(f2(f3(f4(f5(f6(f7(f8.apply(this, arguments)))))))));
101
- };
102
- }
103
- case 10: {
104
- return function() {
105
- return f0(f1(f2(f3(f4(f5(f6(f7(f8(f9.apply(this, arguments))))))))));
106
- };
107
- }
108
- }
6
+ switch (arguments.length) {
7
+ case 1: return f0;
8
+ case 2: return function() {
9
+ return f0(f1.apply(this, arguments));
10
+ };
11
+ case 3: return function() {
12
+ return f0(f1(f2.apply(this, arguments)));
13
+ };
14
+ case 4: return function() {
15
+ return f0(f1(f2(f3.apply(this, arguments))));
16
+ };
17
+ case 5: return function() {
18
+ return f0(f1(f2(f3(f4.apply(this, arguments)))));
19
+ };
20
+ case 6: return function() {
21
+ return f0(f1(f2(f3(f4(f5.apply(this, arguments))))));
22
+ };
23
+ case 7: return function() {
24
+ return f0(f1(f2(f3(f4(f5(f6.apply(this, arguments)))))));
25
+ };
26
+ case 8: return function() {
27
+ return f0(f1(f2(f3(f4(f5(f6(f7.apply(this, arguments))))))));
28
+ };
29
+ case 9: return function() {
30
+ return f0(f1(f2(f3(f4(f5(f6(f7(f8.apply(this, arguments)))))))));
31
+ };
32
+ case 10: return function() {
33
+ return f0(f1(f2(f3(f4(f5(f6(f7(f8(f9.apply(this, arguments))))))))));
34
+ };
35
+ }
109
36
  }
110
-
111
- // src/Composition/converge.ts
37
+ //#endregion
38
+ //#region src/Composition/converge.ts
112
39
  function converge(f, transformers) {
113
- return (a) => f(...transformers.map((t) => t(a)));
40
+ return (a) => f(...transformers.map((t) => t(a)));
114
41
  }
115
-
116
- // src/Composition/curry.ts
117
- var curry = (f) => (a) => (b) => f(a, b);
118
- var curry3 = (f) => (a) => (b) => (c) => f(a, b, c);
119
- var curry4 = (f) => (a) => (b) => (c) => (d) => f(a, b, c, d);
120
-
121
- // src/Composition/flip.ts
122
- var flip = (f) => (b) => (a) => f(a)(b);
123
-
124
- // src/Composition/flow.ts
42
+ //#endregion
43
+ //#region src/Composition/curry.ts
44
+ /**
45
+ * Converts a multi-argument function into a curried function.
46
+ * The inverse of `uncurry`.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * const add = (a: number, b: number) => a + b;
51
+ * const curriedAdd = curry(add);
52
+ * curriedAdd(1)(2); // 3
53
+ *
54
+ * // Partial application
55
+ * const addTen = curriedAdd(10);
56
+ * addTen(5); // 15
57
+ * ```
58
+ *
59
+ * @see {@link uncurry} for the inverse operation
60
+ * @see {@link curry3} for 3-argument functions
61
+ * @see {@link curry4} for 4-argument functions
62
+ */
63
+ const curry = (f) => (a) => (b) => f(a, b);
64
+ /**
65
+ * Converts a 3-argument function into a curried function.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * const add3 = (a: number, b: number, c: number) => a + b + c;
70
+ * const curriedAdd3 = curry3(add3);
71
+ * curriedAdd3(1)(2)(3); // 6
72
+ * ```
73
+ */
74
+ const curry3 = (f) => (a) => (b) => (c) => f(a, b, c);
75
+ /**
76
+ * Converts a 4-argument function into a curried function.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * const add4 = (a: number, b: number, c: number, d: number) => a + b + c + d;
81
+ * const curriedAdd4 = curry4(add4);
82
+ * curriedAdd4(1)(2)(3)(4); // 10
83
+ * ```
84
+ */
85
+ const curry4 = (f) => (a) => (b) => (c) => (d) => f(a, b, c, d);
86
+ //#endregion
87
+ //#region src/Composition/flip.ts
88
+ /**
89
+ * Flips the order of arguments for a curried binary function.
90
+ * Converts a data-last function to data-first.
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * // Original data-last (for pipe)
95
+ * pipe(
96
+ * Maybe.make.some(5),
97
+ * Maybe.map(n => n * 2)
98
+ * ); // Some(10)
99
+ *
100
+ * // Flipped to data-first
101
+ * const mapFirst = flip(Maybe.map);
102
+ * mapFirst(Maybe.make.some(5))(n => n * 2); // Some(10)
103
+ * ```
104
+ *
105
+ * @see {@link uncurry} for converting curried functions to multi-argument functions
106
+ */
107
+ const flip = (f) => (b) => (a) => f(a)(b);
108
+ //#endregion
109
+ //#region src/Composition/flow.ts
125
110
  function flow(ab, bc, cd, de, ef, fg, gh, hi, ij, jk) {
126
- const len = arguments.length;
127
- switch (len) {
128
- case 0: {
129
- return function(...args) {
130
- return args[0];
131
- };
132
- }
133
- case 1: {
134
- return ab;
135
- }
136
- case 2: {
137
- return function() {
138
- return bc(ab.apply(this, arguments));
139
- };
140
- }
141
- case 3: {
142
- return function() {
143
- return cd(bc(ab.apply(this, arguments)));
144
- };
145
- }
146
- case 4: {
147
- return function() {
148
- return de(cd(bc(ab.apply(this, arguments))));
149
- };
150
- }
151
- case 5: {
152
- return function() {
153
- return ef(de(cd(bc(ab.apply(this, arguments)))));
154
- };
155
- }
156
- case 6: {
157
- return function() {
158
- return fg(ef(de(cd(bc(ab.apply(this, arguments))))));
159
- };
160
- }
161
- case 7: {
162
- return function() {
163
- return gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))));
164
- };
165
- }
166
- case 8: {
167
- return function() {
168
- return hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments))))))));
169
- };
170
- }
171
- case 9: {
172
- return function() {
173
- return ij(hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))))));
174
- };
175
- }
176
- case 10: {
177
- return function() {
178
- return jk(ij(hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments))))))))));
179
- };
180
- }
181
- }
111
+ switch (arguments.length) {
112
+ case 0: return function(...args) {
113
+ return args[0];
114
+ };
115
+ case 1: return ab;
116
+ case 2: return function() {
117
+ return bc(ab.apply(this, arguments));
118
+ };
119
+ case 3: return function() {
120
+ return cd(bc(ab.apply(this, arguments)));
121
+ };
122
+ case 4: return function() {
123
+ return de(cd(bc(ab.apply(this, arguments))));
124
+ };
125
+ case 5: return function() {
126
+ return ef(de(cd(bc(ab.apply(this, arguments)))));
127
+ };
128
+ case 6: return function() {
129
+ return fg(ef(de(cd(bc(ab.apply(this, arguments))))));
130
+ };
131
+ case 7: return function() {
132
+ return gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))));
133
+ };
134
+ case 8: return function() {
135
+ return hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments))))))));
136
+ };
137
+ case 9: return function() {
138
+ return ij(hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))))));
139
+ };
140
+ case 10: return function() {
141
+ return jk(ij(hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments))))))))));
142
+ };
143
+ }
182
144
  }
183
- var when = (predicate, onTrue) => (a) => predicate(a) ? onTrue(a) : a;
184
- var unless = (predicate, onFalse) => (a) => predicate(a) ? a : onFalse(a);
185
- var either = (predicate, onTrue, onFalse) => (a) => predicate(a) ? onTrue(a) : onFalse(a);
186
- var struct = (fields) => (a) => {
187
- const result = {};
188
- for (const key of Object.keys(fields)) {
189
- result[key] = fields[key](a);
190
- }
191
- return result;
145
+ const when$1 = (predicate, onTrue) => (a) => predicate(a) ? onTrue(a) : a;
146
+ const unless$1 = (predicate, onFalse) => (a) => predicate(a) ? a : onFalse(a);
147
+ const either$1 = (predicate, onTrue, onFalse) => (a) => predicate(a) ? onTrue(a) : onFalse(a);
148
+ const struct$1 = (fields) => (a) => {
149
+ const result = {};
150
+ for (const key of Object.keys(fields)) result[key] = fields[key](a);
151
+ return result;
192
152
  };
193
- function safe(...fns) {
194
- return (a) => {
195
- let result = a;
196
- if (result === null || result === void 0) {
197
- return result;
198
- }
199
- for (const fn of fns) {
200
- result = fn(result);
201
- if (result === null || result === void 0) {
202
- return result;
203
- }
204
- }
205
- return result;
206
- };
153
+ function safe$1(...fns) {
154
+ return (a) => {
155
+ let result = a;
156
+ if (result === null || result === void 0) return result;
157
+ for (const fn of fns) {
158
+ result = fn(result);
159
+ if (result === null || result === void 0) return result;
160
+ }
161
+ return result;
162
+ };
207
163
  }
208
- function async(...fns) {
209
- return async (a) => {
210
- let result = await a;
211
- for (const fn of fns) {
212
- result = await fn(result);
213
- }
214
- return result;
215
- };
164
+ function async$2(...fns) {
165
+ return async (a) => {
166
+ let result = await a;
167
+ for (const fn of fns) result = await fn(result);
168
+ return result;
169
+ };
216
170
  }
217
- flow.when = when;
218
- flow.unless = unless;
219
- flow.either = either;
220
- flow.struct = struct;
221
- flow.safe = safe;
222
- flow.async = async;
171
+ flow.when = when$1;
172
+ flow.unless = unless$1;
173
+ flow.either = either$1;
174
+ flow.struct = struct$1;
175
+ flow.safe = safe$1;
176
+ flow.async = async$2;
223
177
  flow.try = (f, onError) => (a) => {
224
- try {
225
- return f(a);
226
- } catch (error) {
227
- return onError(error, a);
228
- }
229
- };
230
-
231
- // src/Composition/fn.ts
232
- var identity = (a) => a;
233
- var constant = (a) => () => a;
234
- var constTrue = () => true;
235
- var constFalse = () => false;
236
- var constNull = () => null;
237
- var constUndefined = () => void 0;
238
- var constVoid = () => {
178
+ try {
179
+ return f(a);
180
+ } catch (error) {
181
+ return onError(error, a);
182
+ }
239
183
  };
240
- var and = (p1, p2) => (...args) => p1(...args) && p2(...args);
241
- var or = (p1, p2) => (...args) => p1(...args) || p2(...args);
242
- var once = (f) => {
243
- let called = false;
244
- let result;
245
- return () => {
246
- if (!called) {
247
- result = f();
248
- called = true;
249
- }
250
- return result;
251
- };
184
+ //#endregion
185
+ //#region src/Composition/fn.ts
186
+ /**
187
+ * Returns the value unchanged. The identity function.
188
+ *
189
+ * @example
190
+ * ```ts
191
+ * identity(42); // 42
192
+ * pipe(Maybe.make.some(5), Maybe.fold(() => 0, identity)); // 5
193
+ * ```
194
+ */
195
+ const identity = (a) => a;
196
+ /**
197
+ * Creates a function that always returns the given value, ignoring its argument.
198
+ *
199
+ * @example
200
+ * ```ts
201
+ * const always42 = constant(42);
202
+ * always42(); // 42
203
+ * [1, 2, 3].map(constant("x")); // ["x", "x", "x"]
204
+ * ```
205
+ */
206
+ const constant = (a) => () => a;
207
+ /**
208
+ * Always returns `true`.
209
+ *
210
+ * @example
211
+ * ```ts
212
+ * constTrue(); // true
213
+ * ```
214
+ */
215
+ const constTrue = () => true;
216
+ /**
217
+ * Always returns `false`.
218
+ *
219
+ * @example
220
+ * ```ts
221
+ * constFalse(); // false
222
+ * ```
223
+ */
224
+ const constFalse = () => false;
225
+ /**
226
+ * Always returns `null`.
227
+ *
228
+ * @example
229
+ * ```ts
230
+ * constNull(); // null
231
+ * ```
232
+ */
233
+ const constNull = () => null;
234
+ /**
235
+ * Always returns `undefined`.
236
+ *
237
+ * @example
238
+ * ```ts
239
+ * constUndefined(); // undefined
240
+ * ```
241
+ */
242
+ const constUndefined = () => void 0;
243
+ /**
244
+ * Always returns `void`.
245
+ *
246
+ * @example
247
+ * ```ts
248
+ * constVoid(); // undefined
249
+ * ```
250
+ */
251
+ const constVoid = () => {};
252
+ /**
253
+ * Combines two predicates with logical AND.
254
+ *
255
+ * @example
256
+ * ```ts
257
+ * const isPositive = (n: number) => n > 0;
258
+ * const isEven = (n: number) => n % 2 === 0;
259
+ * const isPositiveEven = and(isPositive, isEven);
260
+ *
261
+ * isPositiveEven(4); // true
262
+ * isPositiveEven(-2); // false
263
+ * isPositiveEven(3); // false
264
+ * ```
265
+ */
266
+ const and = (p1, p2) => (...args) => p1(...args) && p2(...args);
267
+ /**
268
+ * Combines two predicates with logical OR.
269
+ *
270
+ * @example
271
+ * ```ts
272
+ * const isNegative = (n: number) => n < 0;
273
+ * const isZero = (n: number) => n === 0;
274
+ * const isNonPositive = or(isNegative, isZero);
275
+ *
276
+ * isNonPositive(-1); // true
277
+ * isNonPositive(0); // true
278
+ * isNonPositive(1); // false
279
+ * ```
280
+ */
281
+ const or = (p1, p2) => (...args) => p1(...args) || p2(...args);
282
+ /**
283
+ * Creates a function that executes at most once.
284
+ * Subsequent calls return the cached result from the first execution.
285
+ *
286
+ * @example
287
+ * ```ts
288
+ * let count = 0;
289
+ * const initOnce = once(() => { count++; return "initialized"; });
290
+ *
291
+ * initOnce(); // "initialized", count === 1
292
+ * initOnce(); // "initialized", count === 1 (not called again)
293
+ * ```
294
+ */
295
+ const once = (f) => {
296
+ let called = false;
297
+ let result;
298
+ return () => {
299
+ if (!called) {
300
+ result = f();
301
+ called = true;
302
+ }
303
+ return result;
304
+ };
252
305
  };
253
- var defaultTo = (fallback) => (a) => a === null || a === void 0 ? fallback : a;
254
- var tuple = (f) => (args) => f(...args);
255
- var untuple = (f) => (...args) => f(args);
256
-
257
- // src/Composition/juxt.ts
306
+ /**
307
+ * Returns a fallback value if the input is null or undefined; otherwise returns the input value.
308
+ * Highly useful as a data-last default value step inside pipelines.
309
+ *
310
+ * @example
311
+ * ```ts
312
+ * const getName = flow(
313
+ * (u: { name?: string | null }) => u.name,
314
+ * defaultTo("Guest"),
315
+ * (name: string) => name.toUpperCase()
316
+ * ); // returns string
317
+ * ```
318
+ */
319
+ const defaultTo = (fallback) => (a) => a === null || a === void 0 ? fallback : a;
320
+ /**
321
+ * Converts a function taking multiple arguments into a function taking a single tuple argument.
322
+ *
323
+ * @example
324
+ * ```ts
325
+ * const add = (a: number, b: number) => a + b;
326
+ * const addTuple = tuple(add);
327
+ * addTuple([2, 3]); // 5
328
+ * ```
329
+ */
330
+ const tuple = (f) => (args) => f(...args);
331
+ /**
332
+ * Converts a function taking a single tuple argument into a function taking multiple arguments.
333
+ *
334
+ * @example
335
+ * ```ts
336
+ * const addTuple = ([a, b]: readonly [number, number]) => a + b;
337
+ * const add = untuple(addTuple);
338
+ * add(2, 3); // 5
339
+ * ```
340
+ */
341
+ const untuple = (f) => (...args) => f(args);
342
+ //#endregion
343
+ //#region src/Composition/juxt.ts
258
344
  function juxt(fns) {
259
- return (a) => fns.map((f) => f(a));
345
+ return (a) => fns.map((f) => f(a));
260
346
  }
261
-
262
- // src/Composition/memoize.ts
263
- var memoize = (f, options) => {
264
- const cache = /* @__PURE__ */ new Map();
265
- const keyFn = options?.key ?? ((a) => a);
266
- const maxSize = options?.maxSize;
267
- return (a) => {
268
- const key = keyFn(a);
269
- if (cache.has(key)) {
270
- const cached = cache.get(key);
271
- if (maxSize !== void 0) {
272
- cache.delete(key);
273
- cache.set(key, cached);
274
- }
275
- return cached;
276
- }
277
- const result = f(a);
278
- cache.set(key, result);
279
- if (maxSize !== void 0 && cache.size > maxSize) {
280
- for (const k of cache.keys()) {
281
- cache.delete(k);
282
- break;
283
- }
284
- }
285
- return result;
286
- };
347
+ //#endregion
348
+ //#region src/Composition/memoize.ts
349
+ /**
350
+ * Creates a memoized version of a function that caches results.
351
+ * Subsequent calls with the same argument return the cached result.
352
+ *
353
+ * By default, uses the argument directly as the cache key.
354
+ * For complex arguments, provide a custom `keyFn` to generate cache keys.
355
+ *
356
+ * @example
357
+ * ```ts
358
+ * // Basic usage
359
+ * const expensive = memoize((n: number) => {
360
+ * console.log("Computing...");
361
+ * return n * 2;
362
+ * });
363
+ *
364
+ * expensive(5); // logs "Computing...", returns 10
365
+ * expensive(5); // returns 10 (cached, no log)
366
+ * expensive(3); // logs "Computing...", returns 6
367
+ *
368
+ * // With custom key function for objects
369
+ * const fetchUser = memoize(
370
+ * (opts: { id: string }) => fetch(`/users/${opts.id}`),
371
+ * { key: (opts) => opts.id }
372
+ * );
373
+ * // With bounded cache size (LRU eviction)
374
+ * const bounded = memoize(
375
+ * (n: number) => n * 2,
376
+ * { maxSize: 100 }
377
+ * );
378
+ * ```
379
+ */
380
+ const memoize = (f, options) => {
381
+ const cache = /* @__PURE__ */ new Map();
382
+ const keyFn = options?.key ?? ((a) => a);
383
+ const maxSize = options?.maxSize;
384
+ return (a) => {
385
+ const key = keyFn(a);
386
+ if (cache.has(key)) {
387
+ const cached = cache.get(key);
388
+ if (maxSize !== void 0) {
389
+ cache.delete(key);
390
+ cache.set(key, cached);
391
+ }
392
+ return cached;
393
+ }
394
+ const result = f(a);
395
+ cache.set(key, result);
396
+ if (maxSize !== void 0 && cache.size > maxSize) for (const k of cache.keys()) {
397
+ cache.delete(k);
398
+ break;
399
+ }
400
+ return result;
401
+ };
287
402
  };
288
- var memoizeWeak = (f) => {
289
- const cache = /* @__PURE__ */ new WeakMap();
290
- return (a) => {
291
- if (cache.has(a)) {
292
- return cache.get(a);
293
- }
294
- const result = f(a);
295
- cache.set(a, result);
296
- return result;
297
- };
403
+ /**
404
+ * Creates a memoized version of a function using WeakMap.
405
+ * Only works with object arguments, but allows garbage collection
406
+ * of cached values when keys are no longer referenced.
407
+ *
408
+ * @example
409
+ * ```ts
410
+ * type User = { id: number; name: string };
411
+ * const expensiveOperation = (u: User) => u.name.toUpperCase();
412
+ *
413
+ * const processUser = memoizeWeak((user: User) => {
414
+ * return expensiveOperation(user);
415
+ * });
416
+ *
417
+ * const user = { id: 1, name: "Alice" };
418
+ * processUser(user); // computed
419
+ * processUser(user); // cached
420
+ * // When `user` is garbage collected, cached result is too
421
+ * ```
422
+ */
423
+ const memoizeWeak = (f) => {
424
+ const cache = /* @__PURE__ */ new WeakMap();
425
+ return (a) => {
426
+ if (cache.has(a)) return cache.get(a);
427
+ const result = f(a);
428
+ cache.set(a, result);
429
+ return result;
430
+ };
298
431
  };
299
-
300
- // src/Composition/not.ts
301
- var not = (predicate) => (...args) => !predicate(...args);
302
-
303
- // src/Composition/on.ts
304
- var on = (f, g) => (a, b) => f(g(a), g(b));
305
-
306
- // src/Composition/pipe.ts
432
+ //#endregion
433
+ //#region src/Composition/not.ts
434
+ /**
435
+ * Negates a predicate function.
436
+ * Returns a new predicate that returns true when the original returns false, and vice versa.
437
+ *
438
+ * @example
439
+ * ```ts
440
+ * const isEven = (n: number) => n % 2 === 0;
441
+ * const isOdd = not(isEven);
442
+ *
443
+ * isOdd(3); // true
444
+ * isOdd(4); // false
445
+ *
446
+ * // With array methods
447
+ * const numbers = [1, 2, 3, 4, 5];
448
+ * numbers.filter(not(isEven)); // [1, 3, 5]
449
+ *
450
+ * // In pipelines
451
+ * const users = [{ name: "Alice", isAdmin: false }, { name: "Bob", isAdmin: true }];
452
+ * const isAdmin = (u: { name: string; isAdmin: boolean }) => u.isAdmin;
453
+ * pipe(
454
+ * users,
455
+ * Arr.filter(not(isAdmin)),
456
+ * Arr.map((u: { name: string; isAdmin: boolean }) => u.name)
457
+ * );
458
+ * ```
459
+ */
460
+ const not = (predicate) => (...args) => !predicate(...args);
461
+ //#endregion
462
+ //#region src/Composition/on.ts
463
+ /**
464
+ * Applies a projection to both arguments of a binary function before calling it.
465
+ * Most useful for building comparators and equality checks over projected values.
466
+ *
467
+ * @example
468
+ * ```ts
469
+ * const byLength = on((a: number, b: number) => a - b, (s: string) => s.length);
470
+ *
471
+ * ["banana", "fig", "apple"].sort(byLength); // ["fig", "apple", "banana"]
472
+ * ```
473
+ */
474
+ const on = (f, g) => (a, b) => f(g(a), g(b));
475
+ //#endregion
476
+ //#region src/Composition/pipe.ts
307
477
  function pipe(a, ab, bc, cd, de, ef, fg, gh, hi, ij, jk) {
308
- switch (arguments.length) {
309
- case 1: {
310
- return a;
311
- }
312
- case 2: {
313
- return ab(a);
314
- }
315
- case 3: {
316
- return bc(ab(a));
317
- }
318
- case 4: {
319
- return cd(bc(ab(a)));
320
- }
321
- case 5: {
322
- return de(cd(bc(ab(a))));
323
- }
324
- case 6: {
325
- return ef(de(cd(bc(ab(a)))));
326
- }
327
- case 7: {
328
- return fg(ef(de(cd(bc(ab(a))))));
329
- }
330
- case 8: {
331
- return gh(fg(ef(de(cd(bc(ab(a)))))));
332
- }
333
- case 9: {
334
- return hi(gh(fg(ef(de(cd(bc(ab(a))))))));
335
- }
336
- case 10: {
337
- return ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))));
338
- }
339
- case 11: {
340
- return jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))));
341
- }
342
- }
478
+ switch (arguments.length) {
479
+ case 1: return a;
480
+ case 2: return ab(a);
481
+ case 3: return bc(ab(a));
482
+ case 4: return cd(bc(ab(a)));
483
+ case 5: return de(cd(bc(ab(a))));
484
+ case 6: return ef(de(cd(bc(ab(a)))));
485
+ case 7: return fg(ef(de(cd(bc(ab(a))))));
486
+ case 8: return gh(fg(ef(de(cd(bc(ab(a)))))));
487
+ case 9: return hi(gh(fg(ef(de(cd(bc(ab(a))))))));
488
+ case 10: return ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))));
489
+ case 11: return jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))));
490
+ }
343
491
  }
344
- var when2 = (predicate, onTrue) => (a) => predicate(a) ? onTrue(a) : a;
345
- var unless2 = (predicate, onFalse) => (a) => predicate(a) ? a : onFalse(a);
346
- var either2 = (predicate, onTrue, onFalse) => (a) => predicate(a) ? onTrue(a) : onFalse(a);
347
- var struct2 = (fields) => (a) => {
348
- const result = {};
349
- for (const key of Object.keys(fields)) {
350
- result[key] = fields[key](a);
351
- }
352
- return result;
492
+ const when = (predicate, onTrue) => (a) => predicate(a) ? onTrue(a) : a;
493
+ const unless = (predicate, onFalse) => (a) => predicate(a) ? a : onFalse(a);
494
+ const either = (predicate, onTrue, onFalse) => (a) => predicate(a) ? onTrue(a) : onFalse(a);
495
+ const struct = (fields) => (a) => {
496
+ const result = {};
497
+ for (const key of Object.keys(fields)) result[key] = fields[key](a);
498
+ return result;
353
499
  };
354
- function safe2(a, ...fns) {
355
- let result = a;
356
- if (result === null || result === void 0) {
357
- return result;
358
- }
359
- for (const fn of fns) {
360
- result = fn(result);
361
- if (result === null || result === void 0) {
362
- return result;
363
- }
364
- }
365
- return result;
500
+ function safe(a, ...fns) {
501
+ let result = a;
502
+ if (result === null || result === void 0) return result;
503
+ for (const fn of fns) {
504
+ result = fn(result);
505
+ if (result === null || result === void 0) return result;
506
+ }
507
+ return result;
366
508
  }
367
- async function async2(a, ...fns) {
368
- let result = await a;
369
- for (const fn of fns) {
370
- result = await fn(result);
371
- }
372
- return result;
509
+ async function async$1(a, ...fns) {
510
+ let result = await a;
511
+ for (const fn of fns) result = await fn(result);
512
+ return result;
373
513
  }
374
- pipe.when = when2;
375
- pipe.unless = unless2;
376
- pipe.either = either2;
377
- pipe.struct = struct2;
378
- pipe.safe = safe2;
379
- pipe.async = async2;
514
+ pipe.when = when;
515
+ pipe.unless = unless;
516
+ pipe.either = either;
517
+ pipe.struct = struct;
518
+ pipe.safe = safe;
519
+ pipe.async = async$1;
380
520
  pipe.try = (f, onError) => (a) => {
381
- try {
382
- return f(a);
383
- } catch (error) {
384
- return onError(error, a);
385
- }
386
- };
387
-
388
- // src/Composition/tap.ts
389
- var import_node_util = require("util");
390
-
391
- // src/Types/Brand.ts
392
- var Brand = {
393
- /**
394
- * Returns a constructor that wraps a value of type T in brand K.
395
- * The resulting function performs an unchecked cast — only use when the raw
396
- * value is known to satisfy the brand's invariants.
397
- *
398
- * @example
399
- * ```ts
400
- * type PositiveNumber = Brand<"PositiveNumber", number>;
401
- * const toPositiveNumber = Brand.wrap<"PositiveNumber", number>();
402
- *
403
- * const n: PositiveNumber = toPositiveNumber(42);
404
- * ```
405
- */
406
- wrap: () => (value) => value,
407
- /**
408
- * Strips the brand and returns the underlying value.
409
- * Since Brand<K, T> extends T this is rarely needed, but can improve readability.
410
- *
411
- * @example
412
- * ```ts
413
- * type UserId = Brand<"UserId", string>;
414
- * const toUserId = Brand.wrap<"UserId", string>();
415
- * const userId: UserId = toUserId("user-123");
416
- * const raw: string = Brand.unwrap(userId); // "user-123"
417
- * ```
418
- */
419
- unwrap: (branded) => branded
420
- };
421
-
422
- // src/Types/Duration.ts
423
- var wrap = Brand.wrap();
424
- var Duration = {
425
- /**
426
- * Creates a Duration from milliseconds.
427
- *
428
- * @example
429
- * ```ts
430
- * Duration.milliseconds(500); // 500ms Duration
431
- * ```
432
- */
433
- milliseconds: (ms) => wrap(ms),
434
- /**
435
- * Creates a Duration from seconds.
436
- *
437
- * @example
438
- * ```ts
439
- * Duration.seconds(2); // 2000ms Duration
440
- * ```
441
- */
442
- seconds: (s) => wrap(s * 1e3),
443
- /**
444
- * Creates a Duration from minutes.
445
- *
446
- * @example
447
- * ```ts
448
- * Duration.minutes(5); // 300000ms Duration
449
- * ```
450
- */
451
- minutes: (m) => wrap(m * 60 * 1e3),
452
- /**
453
- * Creates a Duration from hours.
454
- *
455
- * @example
456
- * ```ts
457
- * Duration.hours(1); // 3600000ms Duration
458
- * ```
459
- */
460
- hours: (h) => wrap(h * 60 * 60 * 1e3),
461
- /**
462
- * Creates a Duration from days.
463
- *
464
- * @example
465
- * ```ts
466
- * Duration.days(1); // 86400000ms Duration
467
- * ```
468
- */
469
- days: (d) => wrap(d * 24 * 60 * 60 * 1e3),
470
- // --- to ---
471
- to: {
472
- /**
473
- * Converts a Duration back to raw milliseconds.
474
- *
475
- * @example
476
- * ```ts
477
- * Duration.to.milliseconds(Duration.seconds(2)); // 2000
478
- * ```
479
- */
480
- milliseconds: (d) => Brand.unwrap(d),
481
- /**
482
- * Converts a Duration to seconds.
483
- *
484
- * @example
485
- * ```ts
486
- * Duration.to.seconds(Duration.milliseconds(2500)); // 2.5
487
- * ```
488
- */
489
- seconds: (d) => Brand.unwrap(d) / 1e3,
490
- /**
491
- * Converts a Duration to minutes.
492
- *
493
- * @example
494
- * ```ts
495
- * Duration.to.minutes(Duration.seconds(120)); // 2
496
- * ```
497
- */
498
- minutes: (d) => Brand.unwrap(d) / (60 * 1e3),
499
- /**
500
- * Converts a Duration to hours.
501
- *
502
- * @example
503
- * ```ts
504
- * Duration.to.hours(Duration.minutes(90)); // 1.5
505
- * ```
506
- */
507
- hours: (d) => Brand.unwrap(d) / (60 * 60 * 1e3),
508
- /**
509
- * Converts a Duration to days.
510
- *
511
- * @example
512
- * ```ts
513
- * Duration.to.days(Duration.hours(36)); // 1.5
514
- * ```
515
- */
516
- days: (d) => Brand.unwrap(d) / (24 * 60 * 60 * 1e3)
517
- },
518
- /**
519
- * Adds two Durations together.
520
- *
521
- * @example
522
- * ```ts
523
- * pipe(Duration.seconds(1), Duration.add(Duration.milliseconds(500))); // 1500ms
524
- * ```
525
- */
526
- add: (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other)),
527
- /**
528
- * Subtracts the other Duration from this one.
529
- *
530
- * @example
531
- * ```ts
532
- * pipe(Duration.seconds(1), Duration.subtract(Duration.milliseconds(500))); // 500ms
533
- * ```
534
- */
535
- subtract: (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other))
521
+ try {
522
+ return f(a);
523
+ } catch (error) {
524
+ return onError(error, a);
525
+ }
536
526
  };
537
-
538
- // src/Composition/tap.ts
527
+ //#endregion
528
+ //#region src/Composition/tap.ts
529
+ /**
530
+ * Executes a side effect function and returns the original value unchanged.
531
+ * Useful for logging, debugging, or other side effects within a pipeline.
532
+ *
533
+ * @example
534
+ * ```ts
535
+ * // Debugging a pipeline
536
+ * pipe(
537
+ * Maybe.make.some(5),
538
+ * tap(x => console.log("Before map:", x)),
539
+ * Maybe.map(n => n * 2),
540
+ * tap(x => console.log("After map:", x)),
541
+ * Maybe.getOrElse(() => 0)
542
+ * );
543
+ * // logs: "Before map: { kind: 'Some', value: 5 }"
544
+ * // logs: "After map: { kind: 'Some', value: 10 }"
545
+ * // returns: 10
546
+ *
547
+ * // Collecting intermediate values
548
+ * const values: number[] = [];
549
+ * pipe(
550
+ * [1, 2, 3],
551
+ * arr => arr.map(n => n * 2),
552
+ * tap(arr => values.push(...arr))
553
+ * );
554
+ * ```
555
+ *
556
+ * @see {@link Maybe.tap} for Maybe-specific tap that only runs on Some
557
+ */
539
558
  function tap(f) {
540
- return (a) => {
541
- f(a);
542
- return a;
543
- };
559
+ return (a) => {
560
+ f(a);
561
+ return a;
562
+ };
544
563
  }
545
- var log = (options) => (a) => {
546
- const logger = options?.logger ?? console.log;
547
- const formatter = options?.formatter ?? ((val) => {
548
- try {
549
- return typeof val === "object" && val !== null ? JSON.stringify(val) : String(val);
550
- } catch {
551
- return String(val);
552
- }
553
- });
554
- const formatted = formatter(a);
555
- if (options?.label !== void 0) {
556
- logger(`[${options.label}]: ${formatted}`);
557
- } else {
558
- logger(formatted);
559
- }
560
- return a;
564
+ /**
565
+ * Logs the piped value to the console or a custom logger, returning the value unchanged.
566
+ *
567
+ * @example
568
+ * ```ts
569
+ * pipe(
570
+ * 42,
571
+ * tap.log(), // logs: 42
572
+ * tap.log({ label: "Count" }) // logs: [Count]: 42
573
+ * );
574
+ * ```
575
+ */
576
+ const log = (options) => (a) => {
577
+ const logger = options?.logger ?? console.log;
578
+ const formatted = (options?.formatter ?? ((val) => {
579
+ try {
580
+ return typeof val === "object" && val !== null ? JSON.stringify(val) : String(val);
581
+ } catch {
582
+ return String(val);
583
+ }
584
+ }))(a);
585
+ if (options?.label !== void 0) logger(`[${options.label}]: ${formatted}`);
586
+ else logger(formatted);
587
+ return a;
561
588
  };
562
- var inspect = (options) => (a) => {
563
- const label = options?.label;
564
- const depth = options?.depth ?? null;
565
- const colors = options?.colors ?? true;
566
- let formatted;
567
- if (typeof import_node_util.inspect === "function") {
568
- formatted = (0, import_node_util.inspect)(a, { depth, colors });
569
- } else {
570
- try {
571
- formatted = JSON.stringify(a, null, 2);
572
- } catch {
573
- formatted = String(a);
574
- }
575
- }
576
- if (label !== void 0) {
577
- console.log(`[${label}]: ${formatted}`);
578
- } else {
579
- console.log(formatted);
580
- }
581
- return a;
589
+ /**
590
+ * Performs a deep structured inspect formatting on the piped value, returning it unchanged.
591
+ * In Node.js environments, this utilizes Node's `node:util` `inspect` utility.
592
+ *
593
+ * @example
594
+ * ```ts
595
+ * pipe(
596
+ * { user: { name: "Alice", details: { age: 30 } } },
597
+ * tap.inspect({ label: "User Object", depth: 2 })
598
+ * );
599
+ * ```
600
+ */
601
+ const inspect = (options) => (a) => {
602
+ const label = options?.label;
603
+ const depth = options?.depth ?? null;
604
+ const colors = options?.colors ?? true;
605
+ let formatted;
606
+ if (typeof node_util.inspect === "function") formatted = (0, node_util.inspect)(a, {
607
+ depth,
608
+ colors
609
+ });
610
+ else try {
611
+ formatted = JSON.stringify(a, null, 2);
612
+ } catch {
613
+ formatted = String(a);
614
+ }
615
+ if (label !== void 0) console.log(`[${label}]: ${formatted}`);
616
+ else console.log(formatted);
617
+ return a;
582
618
  };
583
- var async3 = (fn, options) => (a) => {
584
- const onError = options?.onError ?? console.error;
585
- Promise.resolve(fn(a)).catch((err) => {
586
- onError(err);
587
- });
588
- return a;
619
+ /**
620
+ * Triggers a fire-and-forget asynchronous side effect in the background,
621
+ * returning the piped value immediately and synchronously.
622
+ * Any errors thrown by the async function are caught and forwarded to `onError`.
623
+ *
624
+ * @example
625
+ * ```ts
626
+ * const user = { id: 1 };
627
+ * const saveToDatabase = async (u: typeof user) => {};
628
+ * const logError = (err: unknown) => console.error(err);
629
+ *
630
+ * pipe(
631
+ * user,
632
+ * tap.async(async (u) => {
633
+ * await saveToDatabase(u);
634
+ * }, { onError: (err) => logError(err) })
635
+ * );
636
+ * ```
637
+ */
638
+ const async = (fn, options) => (a) => {
639
+ const onError = options?.onError ?? console.error;
640
+ Promise.resolve(fn(a)).catch((err) => {
641
+ onError(err);
642
+ });
643
+ return a;
589
644
  };
590
- var time = (fn, config) => (a) => {
591
- const start = performance.now();
592
- const triggerFinish = (duration) => {
593
- if (config.label !== void 0) {
594
- console.log(`[${config.label}]: ${Duration.to.milliseconds(duration)}ms`);
595
- } else {
596
- config.onFinish(duration);
597
- }
598
- };
599
- try {
600
- const res = fn(a);
601
- if (res !== null && (typeof res === "object" || typeof res === "function") && typeof res.then === "function") {
602
- res.then(() => {
603
- const duration = Duration.milliseconds(performance.now() - start);
604
- triggerFinish(duration);
605
- }, () => {
606
- const duration = Duration.milliseconds(performance.now() - start);
607
- triggerFinish(duration);
608
- });
609
- } else {
610
- const duration = Duration.milliseconds(performance.now() - start);
611
- triggerFinish(duration);
612
- }
613
- } catch (err) {
614
- const duration = Duration.milliseconds(performance.now() - start);
615
- triggerFinish(duration);
616
- throw err;
617
- }
618
- return a;
645
+ /**
646
+ * Runs a function and measures its execution duration, returning the value unchanged.
647
+ * Supports both synchronous and asynchronous functions. If the timed function returns
648
+ * a Promise, duration measurement resolves asynchronously upon resolution/rejection.
649
+ *
650
+ * @example
651
+ * ```ts
652
+ * const data = [1, 2, 3];
653
+ * const processData = (d: typeof data) => d.map(n => n * 2);
654
+ * const fetchData = async (d: typeof data) => d.length;
655
+ * const metrics = { histogram: (name: string, ms: number) => {} };
656
+ *
657
+ * // Time a synchronous computation
658
+ * pipe(
659
+ * data,
660
+ * tap.time(processData, { label: "sync-process" })
661
+ * );
662
+ *
663
+ * // Time an asynchronous fetch with custom metrics callback
664
+ * pipe(
665
+ * data,
666
+ * tap.time(fetchData, {
667
+ * onFinish: (dur) => metrics.histogram("api.time", Duration.to.milliseconds(dur))
668
+ * })
669
+ * );
670
+ * ```
671
+ */
672
+ const time = (fn, config) => (a) => {
673
+ const start = performance.now();
674
+ const triggerFinish = (duration) => {
675
+ if (config.label !== void 0) console.log(`[${config.label}]: ${require_types.Duration.to.milliseconds(duration)}ms`);
676
+ else config.onFinish(duration);
677
+ };
678
+ try {
679
+ const res = fn(a);
680
+ if (res !== null && (typeof res === "object" || typeof res === "function") && typeof res.then === "function") res.then(() => {
681
+ const duration = require_types.Duration.milliseconds(performance.now() - start);
682
+ triggerFinish(duration);
683
+ }, () => {
684
+ const duration = require_types.Duration.milliseconds(performance.now() - start);
685
+ triggerFinish(duration);
686
+ });
687
+ else triggerFinish(require_types.Duration.milliseconds(performance.now() - start));
688
+ } catch (err) {
689
+ triggerFinish(require_types.Duration.milliseconds(performance.now() - start));
690
+ throw err;
691
+ }
692
+ return a;
619
693
  };
620
694
  tap.log = log;
621
695
  tap.inspect = inspect;
622
- tap.async = async3;
696
+ tap.async = async;
623
697
  tap.time = time;
624
-
625
- // src/Composition/uncurry.ts
698
+ //#endregion
699
+ //#region src/Composition/uncurry.ts
626
700
  function uncurry(f) {
627
- return (...args) => {
628
- const inner = f(...args.slice(0, f.length));
629
- return inner.length === 0 ? inner() : inner(...args.slice(f.length));
630
- };
701
+ return (...args) => {
702
+ const inner = f(...args.slice(0, f.length));
703
+ return inner.length === 0 ? inner() : inner(...args.slice(f.length));
704
+ };
631
705
  }
632
- var uncurry3 = (f) => (a, b, c) => f(a)(b)(c);
633
- var uncurry4 = (f) => (a, b, c, d) => f(a)(b)(c)(d);
634
- // Annotate the CommonJS export names for ESM import in node:
635
- 0 && (module.exports = {
636
- and,
637
- compose,
638
- constFalse,
639
- constNull,
640
- constTrue,
641
- constUndefined,
642
- constVoid,
643
- constant,
644
- converge,
645
- curry,
646
- curry3,
647
- curry4,
648
- defaultTo,
649
- flip,
650
- flow,
651
- identity,
652
- juxt,
653
- memoize,
654
- memoizeWeak,
655
- not,
656
- on,
657
- once,
658
- or,
659
- pipe,
660
- tap,
661
- tuple,
662
- uncurry,
663
- uncurry3,
664
- uncurry4,
665
- untuple
666
- });
706
+ /**
707
+ * Converts a curried 3-argument function into a multi-argument function.
708
+ *
709
+ * @example
710
+ * ```ts
711
+ * const curriedAdd3 = (a: number) => (b: number) => (c: number) => a + b + c;
712
+ * const add3 = uncurry3(curriedAdd3);
713
+ * add3(1, 2, 3); // 6
714
+ * ```
715
+ */
716
+ const uncurry3 = (f) => (a, b, c) => f(a)(b)(c);
717
+ /**
718
+ * Converts a curried 4-argument function into a multi-argument function.
719
+ *
720
+ * @example
721
+ * ```ts
722
+ * const curriedAdd4 = (a: number) => (b: number) => (c: number) => (d: number) => a + b + c + d;
723
+ * const add4 = uncurry4(curriedAdd4);
724
+ * add4(1, 2, 3, 4); // 10
725
+ * ```
726
+ */
727
+ const uncurry4 = (f) => (a, b, c, d) => f(a)(b)(c)(d);
728
+ //#endregion
729
+ exports.and = and;
730
+ exports.compose = compose;
731
+ exports.constFalse = constFalse;
732
+ exports.constNull = constNull;
733
+ exports.constTrue = constTrue;
734
+ exports.constUndefined = constUndefined;
735
+ exports.constVoid = constVoid;
736
+ exports.constant = constant;
737
+ exports.converge = converge;
738
+ exports.curry = curry;
739
+ exports.curry3 = curry3;
740
+ exports.curry4 = curry4;
741
+ exports.defaultTo = defaultTo;
742
+ exports.flip = flip;
743
+ exports.flow = flow;
744
+ exports.identity = identity;
745
+ exports.juxt = juxt;
746
+ exports.memoize = memoize;
747
+ exports.memoizeWeak = memoizeWeak;
748
+ exports.not = not;
749
+ exports.on = on;
750
+ exports.once = once;
751
+ exports.or = or;
752
+ exports.pipe = pipe;
753
+ exports.tap = tap;
754
+ exports.tuple = tuple;
755
+ exports.uncurry = uncurry;
756
+ exports.uncurry3 = uncurry3;
757
+ exports.uncurry4 = uncurry4;
758
+ exports.untuple = untuple;