@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.
- package/LICENCE +28 -0
- package/README.md +1 -1
- package/{types/src/Types/NonEmptyList.d.ts → dist/NonEmptyList-BlGFjor5.d.mts} +4 -3
- package/dist/NonEmptyList-BlGFjor5.d.ts +30 -0
- package/dist/Task-BB8Wmc1J.d.ts +677 -0
- package/dist/Task-ChKyH0pF.d.mts +677 -0
- package/dist/chunk-DBIC62UV.mjs +6 -0
- package/dist/chunk-QPTGO5AS.mjs +150 -0
- package/dist/composition.d.mts +495 -0
- package/dist/composition.d.ts +495 -0
- package/dist/composition.js +188 -0
- package/dist/composition.mjs +135 -0
- package/dist/core.d.mts +2170 -0
- package/dist/core.d.ts +2170 -0
- package/dist/core.js +698 -0
- package/dist/core.mjs +517 -0
- package/dist/types.d.mts +54 -0
- package/{types/src/Types/Brand.d.ts → dist/types.d.ts} +6 -4
- package/dist/types.js +41 -0
- package/dist/types.mjs +14 -0
- package/dist/utils.d.mts +1285 -0
- package/dist/utils.d.ts +1285 -0
- package/dist/utils.js +722 -0
- package/dist/utils.mjs +553 -0
- package/package.json +63 -69
- package/esm/mod.js +0 -3
- package/esm/package.json +0 -3
- package/esm/src/Composition/compose.js +0 -3
- package/esm/src/Composition/converge.js +0 -3
- package/esm/src/Composition/curry.js +0 -42
- package/esm/src/Composition/flip.js +0 -20
- package/esm/src/Composition/flow.js +0 -8
- package/esm/src/Composition/fn.js +0 -85
- package/esm/src/Composition/index.js +0 -13
- package/esm/src/Composition/juxt.js +0 -3
- package/esm/src/Composition/memoize.js +0 -66
- package/esm/src/Composition/not.js +0 -25
- package/esm/src/Composition/on.js +0 -12
- package/esm/src/Composition/pipe.js +0 -3
- package/esm/src/Composition/tap.js +0 -33
- package/esm/src/Composition/uncurry.js +0 -32
- package/esm/src/Core/Deferred.js +0 -30
- package/esm/src/Core/InternalTypes.js +0 -1
- package/esm/src/Core/Lens.js +0 -98
- package/esm/src/Core/Logged.js +0 -111
- package/esm/src/Core/Option.js +0 -191
- package/esm/src/Core/Optional.js +0 -160
- package/esm/src/Core/Predicate.js +0 -133
- package/esm/src/Core/Reader.js +0 -134
- package/esm/src/Core/Refinement.js +0 -115
- package/esm/src/Core/RemoteData.js +0 -211
- package/esm/src/Core/Result.js +0 -170
- package/esm/src/Core/State.js +0 -181
- package/esm/src/Core/Task.js +0 -223
- package/esm/src/Core/TaskOption.js +0 -106
- package/esm/src/Core/TaskResult.js +0 -127
- package/esm/src/Core/TaskValidation.js +0 -128
- package/esm/src/Core/These.js +0 -245
- package/esm/src/Core/Tuple.js +0 -112
- package/esm/src/Core/Validation.js +0 -212
- package/esm/src/Core/index.js +0 -18
- package/esm/src/Types/Brand.js +0 -28
- package/esm/src/Types/NonEmptyList.js +0 -14
- package/esm/src/Types/index.js +0 -2
- package/esm/src/Utils/Arr.js +0 -570
- package/esm/src/Utils/Dict.js +0 -421
- package/esm/src/Utils/Num.js +0 -124
- package/esm/src/Utils/Rec.js +0 -241
- package/esm/src/Utils/Str.js +0 -134
- package/esm/src/Utils/Uniq.js +0 -265
- package/esm/src/Utils/index.js +0 -6
- package/script/mod.js +0 -19
- package/script/package.json +0 -3
- package/script/src/Composition/compose.js +0 -6
- package/script/src/Composition/converge.js +0 -6
- package/script/src/Composition/curry.js +0 -48
- package/script/src/Composition/flip.js +0 -24
- package/script/src/Composition/flow.js +0 -11
- package/script/src/Composition/fn.js +0 -98
- package/script/src/Composition/index.js +0 -29
- package/script/src/Composition/juxt.js +0 -6
- package/script/src/Composition/memoize.js +0 -71
- package/script/src/Composition/not.js +0 -29
- package/script/src/Composition/on.js +0 -16
- package/script/src/Composition/pipe.js +0 -6
- package/script/src/Composition/tap.js +0 -37
- package/script/src/Composition/uncurry.js +0 -38
- package/script/src/Core/Deferred.js +0 -33
- package/script/src/Core/InternalTypes.js +0 -2
- package/script/src/Core/Lens.js +0 -101
- package/script/src/Core/Logged.js +0 -114
- package/script/src/Core/Option.js +0 -194
- package/script/src/Core/Optional.js +0 -163
- package/script/src/Core/Predicate.js +0 -136
- package/script/src/Core/Reader.js +0 -137
- package/script/src/Core/Refinement.js +0 -118
- package/script/src/Core/RemoteData.js +0 -214
- package/script/src/Core/Result.js +0 -173
- package/script/src/Core/State.js +0 -184
- package/script/src/Core/Task.js +0 -226
- package/script/src/Core/TaskOption.js +0 -109
- package/script/src/Core/TaskResult.js +0 -130
- package/script/src/Core/TaskValidation.js +0 -131
- package/script/src/Core/These.js +0 -248
- package/script/src/Core/Tuple.js +0 -115
- package/script/src/Core/Validation.js +0 -215
- package/script/src/Core/index.js +0 -34
- package/script/src/Types/Brand.js +0 -31
- package/script/src/Types/NonEmptyList.js +0 -18
- package/script/src/Types/index.js +0 -18
- package/script/src/Utils/Arr.js +0 -573
- package/script/src/Utils/Dict.js +0 -424
- package/script/src/Utils/Num.js +0 -127
- package/script/src/Utils/Rec.js +0 -244
- package/script/src/Utils/Str.js +0 -137
- package/script/src/Utils/Uniq.js +0 -268
- package/script/src/Utils/index.js +0 -22
- package/types/mod.d.ts +0 -4
- package/types/mod.d.ts.map +0 -1
- package/types/src/Composition/compose.d.ts +0 -33
- package/types/src/Composition/compose.d.ts.map +0 -1
- package/types/src/Composition/converge.d.ts +0 -21
- package/types/src/Composition/converge.d.ts.map +0 -1
- package/types/src/Composition/curry.d.ts +0 -43
- package/types/src/Composition/curry.d.ts.map +0 -1
- package/types/src/Composition/flip.d.ts +0 -21
- package/types/src/Composition/flip.d.ts.map +0 -1
- package/types/src/Composition/flow.d.ts +0 -56
- package/types/src/Composition/flow.d.ts.map +0 -1
- package/types/src/Composition/fn.d.ts +0 -76
- package/types/src/Composition/fn.d.ts.map +0 -1
- package/types/src/Composition/index.d.ts +0 -14
- package/types/src/Composition/index.d.ts.map +0 -1
- package/types/src/Composition/juxt.d.ts +0 -18
- package/types/src/Composition/juxt.d.ts.map +0 -1
- package/types/src/Composition/memoize.d.ts +0 -46
- package/types/src/Composition/memoize.d.ts.map +0 -1
- package/types/src/Composition/not.d.ts +0 -26
- package/types/src/Composition/not.d.ts.map +0 -1
- package/types/src/Composition/on.d.ts +0 -13
- package/types/src/Composition/on.d.ts.map +0 -1
- package/types/src/Composition/pipe.d.ts +0 -56
- package/types/src/Composition/pipe.d.ts.map +0 -1
- package/types/src/Composition/tap.d.ts +0 -31
- package/types/src/Composition/tap.d.ts.map +0 -1
- package/types/src/Composition/uncurry.d.ts +0 -54
- package/types/src/Composition/uncurry.d.ts.map +0 -1
- package/types/src/Core/Deferred.d.ts +0 -49
- package/types/src/Core/Deferred.d.ts.map +0 -1
- package/types/src/Core/InternalTypes.d.ts +0 -23
- package/types/src/Core/InternalTypes.d.ts.map +0 -1
- package/types/src/Core/Lens.d.ts +0 -118
- package/types/src/Core/Lens.d.ts.map +0 -1
- package/types/src/Core/Logged.d.ts +0 -126
- package/types/src/Core/Logged.d.ts.map +0 -1
- package/types/src/Core/Option.d.ts +0 -209
- package/types/src/Core/Option.d.ts.map +0 -1
- package/types/src/Core/Optional.d.ts +0 -158
- package/types/src/Core/Optional.d.ts.map +0 -1
- package/types/src/Core/Predicate.d.ts +0 -161
- package/types/src/Core/Predicate.d.ts.map +0 -1
- package/types/src/Core/Reader.d.ts +0 -156
- package/types/src/Core/Reader.d.ts.map +0 -1
- package/types/src/Core/Refinement.d.ts +0 -138
- package/types/src/Core/Refinement.d.ts.map +0 -1
- package/types/src/Core/RemoteData.d.ts +0 -197
- package/types/src/Core/RemoteData.d.ts.map +0 -1
- package/types/src/Core/Result.d.ts +0 -182
- package/types/src/Core/Result.d.ts.map +0 -1
- package/types/src/Core/State.d.ts +0 -192
- package/types/src/Core/State.d.ts.map +0 -1
- package/types/src/Core/Task.d.ts +0 -219
- package/types/src/Core/Task.d.ts.map +0 -1
- package/types/src/Core/TaskOption.d.ts +0 -121
- package/types/src/Core/TaskOption.d.ts.map +0 -1
- package/types/src/Core/TaskResult.d.ts +0 -119
- package/types/src/Core/TaskResult.d.ts.map +0 -1
- package/types/src/Core/TaskValidation.d.ts +0 -144
- package/types/src/Core/TaskValidation.d.ts.map +0 -1
- package/types/src/Core/These.d.ts +0 -225
- package/types/src/Core/These.d.ts.map +0 -1
- package/types/src/Core/Tuple.d.ts +0 -129
- package/types/src/Core/Tuple.d.ts.map +0 -1
- package/types/src/Core/Validation.d.ts +0 -203
- package/types/src/Core/Validation.d.ts.map +0 -1
- package/types/src/Core/index.d.ts +0 -19
- package/types/src/Core/index.d.ts.map +0 -1
- package/types/src/Types/Brand.d.ts.map +0 -1
- package/types/src/Types/NonEmptyList.d.ts.map +0 -1
- package/types/src/Types/index.d.ts +0 -3
- package/types/src/Types/index.d.ts.map +0 -1
- package/types/src/Utils/Arr.d.ts +0 -403
- package/types/src/Utils/Arr.d.ts.map +0 -1
- package/types/src/Utils/Dict.d.ts +0 -310
- package/types/src/Utils/Dict.d.ts.map +0 -1
- package/types/src/Utils/Num.d.ts +0 -110
- package/types/src/Utils/Num.d.ts.map +0 -1
- package/types/src/Utils/Rec.d.ts +0 -159
- package/types/src/Utils/Rec.d.ts.map +0 -1
- package/types/src/Utils/Str.d.ts +0 -128
- package/types/src/Utils/Str.d.ts.map +0 -1
- package/types/src/Utils/Uniq.d.ts +0 -179
- package/types/src/Utils/Uniq.d.ts.map +0 -1
- package/types/src/Utils/index.d.ts +0 -7
- package/types/src/Utils/index.d.ts.map +0 -1
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.curry4 = exports.curry3 = exports.curry = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Converts a multi-argument function into a curried function.
|
|
6
|
-
* The inverse of `uncurry`.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* const add = (a: number, b: number) => a + b;
|
|
11
|
-
* const curriedAdd = curry(add);
|
|
12
|
-
* curriedAdd(1)(2); // 3
|
|
13
|
-
*
|
|
14
|
-
* // Partial application
|
|
15
|
-
* const addTen = curriedAdd(10);
|
|
16
|
-
* addTen(5); // 15
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* @see {@link uncurry} for the inverse operation
|
|
20
|
-
* @see {@link curry3} for 3-argument functions
|
|
21
|
-
* @see {@link curry4} for 4-argument functions
|
|
22
|
-
*/
|
|
23
|
-
const curry = (f) => (a) => (b) => f(a, b);
|
|
24
|
-
exports.curry = curry;
|
|
25
|
-
/**
|
|
26
|
-
* Converts a 3-argument function into a curried function.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* const add3 = (a: number, b: number, c: number) => a + b + c;
|
|
31
|
-
* const curriedAdd3 = curry3(add3);
|
|
32
|
-
* curriedAdd3(1)(2)(3); // 6
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
const curry3 = (f) => (a) => (b) => (c) => f(a, b, c);
|
|
36
|
-
exports.curry3 = curry3;
|
|
37
|
-
/**
|
|
38
|
-
* Converts a 4-argument function into a curried function.
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```ts
|
|
42
|
-
* const add4 = (a: number, b: number, c: number, d: number) => a + b + c + d;
|
|
43
|
-
* const curriedAdd4 = curry4(add4);
|
|
44
|
-
* curriedAdd4(1)(2)(3)(4); // 10
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
const curry4 = (f) => (a) => (b) => (c) => (d) => f(a, b, c, d);
|
|
48
|
-
exports.curry4 = curry4;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.flip = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Flips the order of arguments for a curried binary function.
|
|
6
|
-
* Converts a data-last function to data-first.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* // Original data-last (for pipe)
|
|
11
|
-
* pipe(
|
|
12
|
-
* Option.some(5),
|
|
13
|
-
* Option.map(n => n * 2)
|
|
14
|
-
* ); // Some(10)
|
|
15
|
-
*
|
|
16
|
-
* // Flipped to data-first
|
|
17
|
-
* const mapFirst = flip(Option.map);
|
|
18
|
-
* mapFirst(Option.some(5))(n => n * 2); // Some(10)
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* @see {@link uncurry} for converting curried functions to multi-argument functions
|
|
22
|
-
*/
|
|
23
|
-
const flip = (f) => (b) => (a) => f(a)(b);
|
|
24
|
-
exports.flip = flip;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.flow = flow;
|
|
4
|
-
function flow(...fns) {
|
|
5
|
-
return (...args) => {
|
|
6
|
-
if (fns.length === 0)
|
|
7
|
-
return args[0];
|
|
8
|
-
const [first, ...rest] = fns;
|
|
9
|
-
return rest.reduce((acc, fn) => fn(acc), first(...args));
|
|
10
|
-
};
|
|
11
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.once = exports.or = exports.and = exports.constVoid = exports.constUndefined = exports.constNull = exports.constFalse = exports.constTrue = exports.constant = exports.identity = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Returns the value unchanged. The identity function.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* identity(42); // 42
|
|
10
|
-
* pipe(Option.some(5), Option.fold(() => 0, identity)); // 5
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
const identity = (a) => a;
|
|
14
|
-
exports.identity = identity;
|
|
15
|
-
/**
|
|
16
|
-
* Creates a function that always returns the given value, ignoring its argument.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```ts
|
|
20
|
-
* const always42 = constant(42);
|
|
21
|
-
* always42(); // 42
|
|
22
|
-
* [1, 2, 3].map(constant("x")); // ["x", "x", "x"]
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
const constant = (a) => () => a;
|
|
26
|
-
exports.constant = constant;
|
|
27
|
-
/** Always returns `true`. */
|
|
28
|
-
const constTrue = () => true;
|
|
29
|
-
exports.constTrue = constTrue;
|
|
30
|
-
/** Always returns `false`. */
|
|
31
|
-
const constFalse = () => false;
|
|
32
|
-
exports.constFalse = constFalse;
|
|
33
|
-
/** Always returns `null`. */
|
|
34
|
-
const constNull = () => null;
|
|
35
|
-
exports.constNull = constNull;
|
|
36
|
-
/** Always returns `undefined`. */
|
|
37
|
-
const constUndefined = () => undefined;
|
|
38
|
-
exports.constUndefined = constUndefined;
|
|
39
|
-
/** Always returns `void`. */
|
|
40
|
-
const constVoid = () => { };
|
|
41
|
-
exports.constVoid = constVoid;
|
|
42
|
-
/**
|
|
43
|
-
* Combines two predicates with logical AND.
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```ts
|
|
47
|
-
* const isPositive = (n: number) => n > 0;
|
|
48
|
-
* const isEven = (n: number) => n % 2 === 0;
|
|
49
|
-
* const isPositiveEven = and(isPositive, isEven);
|
|
50
|
-
*
|
|
51
|
-
* isPositiveEven(4); // true
|
|
52
|
-
* isPositiveEven(-2); // false
|
|
53
|
-
* isPositiveEven(3); // false
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
const and = (p1, p2) => (...args) => p1(...args) && p2(...args);
|
|
57
|
-
exports.and = and;
|
|
58
|
-
/**
|
|
59
|
-
* Combines two predicates with logical OR.
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```ts
|
|
63
|
-
* const isNegative = (n: number) => n < 0;
|
|
64
|
-
* const isZero = (n: number) => n === 0;
|
|
65
|
-
* const isNonPositive = or(isNegative, isZero);
|
|
66
|
-
*
|
|
67
|
-
* isNonPositive(-1); // true
|
|
68
|
-
* isNonPositive(0); // true
|
|
69
|
-
* isNonPositive(1); // false
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
const or = (p1, p2) => (...args) => p1(...args) || p2(...args);
|
|
73
|
-
exports.or = or;
|
|
74
|
-
/**
|
|
75
|
-
* Creates a function that executes at most once.
|
|
76
|
-
* Subsequent calls return the cached result from the first execution.
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* ```ts
|
|
80
|
-
* let count = 0;
|
|
81
|
-
* const initOnce = once(() => { count++; return "initialized"; });
|
|
82
|
-
*
|
|
83
|
-
* initOnce(); // "initialized", count === 1
|
|
84
|
-
* initOnce(); // "initialized", count === 1 (not called again)
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
const once = (f) => {
|
|
88
|
-
let called = false;
|
|
89
|
-
let result;
|
|
90
|
-
return () => {
|
|
91
|
-
if (!called) {
|
|
92
|
-
result = f();
|
|
93
|
-
called = true;
|
|
94
|
-
}
|
|
95
|
-
return result;
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
exports.once = once;
|
|
@@ -1,29 +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("./compose.js"), exports);
|
|
18
|
-
__exportStar(require("./converge.js"), exports);
|
|
19
|
-
__exportStar(require("./curry.js"), exports);
|
|
20
|
-
__exportStar(require("./flip.js"), exports);
|
|
21
|
-
__exportStar(require("./fn.js"), exports);
|
|
22
|
-
__exportStar(require("./flow.js"), exports);
|
|
23
|
-
__exportStar(require("./juxt.js"), exports);
|
|
24
|
-
__exportStar(require("./memoize.js"), exports);
|
|
25
|
-
__exportStar(require("./not.js"), exports);
|
|
26
|
-
__exportStar(require("./on.js"), exports);
|
|
27
|
-
__exportStar(require("./pipe.js"), exports);
|
|
28
|
-
__exportStar(require("./tap.js"), exports);
|
|
29
|
-
__exportStar(require("./uncurry.js"), exports);
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.memoizeWeak = exports.memoize = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Creates a memoized version of a function that caches results.
|
|
6
|
-
* Subsequent calls with the same argument return the cached result.
|
|
7
|
-
*
|
|
8
|
-
* By default, uses the argument directly as the cache key.
|
|
9
|
-
* For complex arguments, provide a custom `keyFn` to generate cache keys.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* // Basic usage
|
|
14
|
-
* const expensive = memoize((n: number) => {
|
|
15
|
-
* console.log("Computing...");
|
|
16
|
-
* return n * 2;
|
|
17
|
-
* });
|
|
18
|
-
*
|
|
19
|
-
* expensive(5); // logs "Computing...", returns 10
|
|
20
|
-
* expensive(5); // returns 10 (cached, no log)
|
|
21
|
-
* expensive(3); // logs "Computing...", returns 6
|
|
22
|
-
*
|
|
23
|
-
* // With custom key function for objects
|
|
24
|
-
* const fetchUser = memoize(
|
|
25
|
-
* (opts: { id: string }) => fetch(`/users/${opts.id}`),
|
|
26
|
-
* opts => opts.id
|
|
27
|
-
* );
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
const memoize = (f, keyFn = (a) => a) => {
|
|
31
|
-
const cache = new Map();
|
|
32
|
-
return (a) => {
|
|
33
|
-
const key = keyFn(a);
|
|
34
|
-
if (cache.has(key)) {
|
|
35
|
-
return cache.get(key);
|
|
36
|
-
}
|
|
37
|
-
const result = f(a);
|
|
38
|
-
cache.set(key, result);
|
|
39
|
-
return result;
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
exports.memoize = memoize;
|
|
43
|
-
/**
|
|
44
|
-
* Creates a memoized version of a function using WeakMap.
|
|
45
|
-
* Only works with object arguments, but allows garbage collection
|
|
46
|
-
* of cached values when keys are no longer referenced.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```ts
|
|
50
|
-
* const processUser = memoizeWeak((user: User) => {
|
|
51
|
-
* return expensiveOperation(user);
|
|
52
|
-
* });
|
|
53
|
-
*
|
|
54
|
-
* const user = { id: 1, name: "Alice" };
|
|
55
|
-
* processUser(user); // computed
|
|
56
|
-
* processUser(user); // cached
|
|
57
|
-
* // When `user` is garbage collected, cached result is too
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
const memoizeWeak = (f) => {
|
|
61
|
-
const cache = new WeakMap();
|
|
62
|
-
return (a) => {
|
|
63
|
-
if (cache.has(a)) {
|
|
64
|
-
return cache.get(a);
|
|
65
|
-
}
|
|
66
|
-
const result = f(a);
|
|
67
|
-
cache.set(a, result);
|
|
68
|
-
return result;
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
exports.memoizeWeak = memoizeWeak;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.not = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Negates a predicate function.
|
|
6
|
-
* Returns a new predicate that returns true when the original returns false, and vice versa.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* const isEven = (n: number) => n % 2 === 0;
|
|
11
|
-
* const isOdd = not(isEven);
|
|
12
|
-
*
|
|
13
|
-
* isOdd(3); // true
|
|
14
|
-
* isOdd(4); // false
|
|
15
|
-
*
|
|
16
|
-
* // With array methods
|
|
17
|
-
* const numbers = [1, 2, 3, 4, 5];
|
|
18
|
-
* numbers.filter(not(isEven)); // [1, 3, 5]
|
|
19
|
-
*
|
|
20
|
-
* // In pipelines
|
|
21
|
-
* pipe(
|
|
22
|
-
* users,
|
|
23
|
-
* Array.filter(not(isAdmin)),
|
|
24
|
-
* Array.map(u => u.name)
|
|
25
|
-
* );
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
const not = (predicate) => (...args) => !predicate(...args);
|
|
29
|
-
exports.not = not;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.on = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Applies a projection to both arguments of a binary function before calling it.
|
|
6
|
-
* Most useful for building comparators and equality checks over projected values.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* const byLength = on((a: number, b: number) => a - b, (s: string) => s.length);
|
|
11
|
-
*
|
|
12
|
-
* ["banana", "fig", "apple"].sort(byLength); // ["fig", "apple", "banana"]
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
const on = (f, g) => (a, b) => f(g(a), g(b));
|
|
16
|
-
exports.on = on;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tap = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Executes a side effect function and returns the original value unchanged.
|
|
6
|
-
* Useful for logging, debugging, or other side effects within a pipeline.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* // Debugging a pipeline
|
|
11
|
-
* pipe(
|
|
12
|
-
* Option.some(5),
|
|
13
|
-
* tap(x => console.log("Before map:", x)),
|
|
14
|
-
* Option.map(n => n * 2),
|
|
15
|
-
* tap(x => console.log("After map:", x)),
|
|
16
|
-
* Option.getOrElse(0)
|
|
17
|
-
* );
|
|
18
|
-
* // logs: "Before map: { kind: 'Some', value: 5 }"
|
|
19
|
-
* // logs: "After map: { kind: 'Some', value: 10 }"
|
|
20
|
-
* // returns: 10
|
|
21
|
-
*
|
|
22
|
-
* // Collecting intermediate values
|
|
23
|
-
* const values: number[] = [];
|
|
24
|
-
* pipe(
|
|
25
|
-
* [1, 2, 3],
|
|
26
|
-
* arr => arr.map(n => n * 2),
|
|
27
|
-
* tap(arr => values.push(...arr))
|
|
28
|
-
* );
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* @see {@link Option.tap} for Option-specific tap that only runs on Some
|
|
32
|
-
*/
|
|
33
|
-
const tap = (f) => (a) => {
|
|
34
|
-
f(a);
|
|
35
|
-
return a;
|
|
36
|
-
};
|
|
37
|
-
exports.tap = tap;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uncurry4 = exports.uncurry3 = void 0;
|
|
4
|
-
exports.uncurry = uncurry;
|
|
5
|
-
// deno-lint-ignore no-explicit-any
|
|
6
|
-
function uncurry(f) {
|
|
7
|
-
// f.length determines the outer arity; inner.length determines the inner arity.
|
|
8
|
-
// The typed overloads guarantee these are 0, 1, or 2 total args.
|
|
9
|
-
// deno-lint-ignore no-explicit-any
|
|
10
|
-
return (...args) => {
|
|
11
|
-
const inner = f(...args.slice(0, f.length));
|
|
12
|
-
return inner.length === 0 ? inner() : inner(...args.slice(f.length));
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Converts a curried 3-argument function into a multi-argument function.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```ts
|
|
20
|
-
* const curriedAdd3 = (a: number) => (b: number) => (c: number) => a + b + c;
|
|
21
|
-
* const add3 = uncurry3(curriedAdd3);
|
|
22
|
-
* add3(1, 2, 3); // 6
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
const uncurry3 = (f) => (a, b, c) => f(a)(b)(c);
|
|
26
|
-
exports.uncurry3 = uncurry3;
|
|
27
|
-
/**
|
|
28
|
-
* Converts a curried 4-argument function into a multi-argument function.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```ts
|
|
32
|
-
* const curriedAdd4 = (a: number) => (b: number) => (c: number) => (d: number) => a + b + c + d;
|
|
33
|
-
* const add4 = uncurry4(curriedAdd4);
|
|
34
|
-
* add4(1, 2, 3, 4); // 10
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
const uncurry4 = (f) => (a, b, c, d) => f(a)(b)(c)(d);
|
|
38
|
-
exports.uncurry4 = uncurry4;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Deferred = void 0;
|
|
4
|
-
const _store = new WeakMap();
|
|
5
|
-
var Deferred;
|
|
6
|
-
(function (Deferred) {
|
|
7
|
-
/**
|
|
8
|
-
* Wraps a `Promise` into a `Deferred`, structurally excluding rejection handlers,
|
|
9
|
-
* `.catch()`, `.finally()`, and chainable `.then()`.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* const d = Deferred.fromPromise(Promise.resolve("hello"));
|
|
14
|
-
* const value = await d; // "hello"
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
Deferred.fromPromise = (p) => {
|
|
18
|
-
const d = ({ then: ((f) => p.then(f)) });
|
|
19
|
-
_store.set(d, p);
|
|
20
|
-
return d;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Converts a `Deferred` back into a `Promise`.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* const p = Deferred.toPromise(Deferred.fromPromise(Promise.resolve(42)));
|
|
28
|
-
* // p is Promise<42>
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
Deferred.toPromise = (d) => _store.get(d) ??
|
|
32
|
-
new Promise((resolve) => d.then(resolve));
|
|
33
|
-
})(Deferred || (exports.Deferred = Deferred = {}));
|
package/script/src/Core/Lens.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Lens = void 0;
|
|
4
|
-
var Lens;
|
|
5
|
-
(function (Lens) {
|
|
6
|
-
/**
|
|
7
|
-
* Constructs a Lens from a getter and a setter.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* const nameLens = Lens.make(
|
|
12
|
-
* (user: User) => user.name,
|
|
13
|
-
* (name) => (user) => ({ ...user, name }),
|
|
14
|
-
* );
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
Lens.make = (get, set) => ({ get, set });
|
|
18
|
-
/**
|
|
19
|
-
* Creates a Lens that focuses on a property of an object.
|
|
20
|
-
* Call with the structure type first, then the key.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```ts
|
|
24
|
-
* const nameLens = Lens.prop<User>()("name");
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
Lens.prop = () => (key) => Lens.make((s) => s[key], (a) => (s) => ({ ...s, [key]: a }));
|
|
28
|
-
/**
|
|
29
|
-
* Reads the focused value from a structure.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```ts
|
|
33
|
-
* pipe(user, Lens.get(nameLens)); // "Alice"
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
Lens.get = (lens) => (s) => lens.get(s);
|
|
37
|
-
/**
|
|
38
|
-
* Replaces the focused value within a structure, returning a new structure.
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```ts
|
|
42
|
-
* pipe(user, Lens.set(nameLens)("Bob")); // new User with name "Bob"
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
Lens.set = (lens) => (a) => (s) => lens.set(a)(s);
|
|
46
|
-
/**
|
|
47
|
-
* Applies a function to the focused value, returning a new structure.
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* ```ts
|
|
51
|
-
* pipe(user, Lens.modify(nameLens)(n => n.toUpperCase())); // "ALICE"
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
Lens.modify = (lens) => (f) => (s) => lens.set(f(lens.get(s)))(s);
|
|
55
|
-
/**
|
|
56
|
-
* Composes two Lenses: focuses through the outer, then through the inner.
|
|
57
|
-
* Use in a pipe chain to build up a deep focus step by step.
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```ts
|
|
61
|
-
* const userCityLens = pipe(
|
|
62
|
-
* Lens.prop<User>()("address"),
|
|
63
|
-
* Lens.andThen(Lens.prop<Address>()("city")),
|
|
64
|
-
* );
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
Lens.andThen = (inner) => (outer) => Lens.make((s) => inner.get(outer.get(s)), (b) => (s) => outer.set(inner.set(b)(outer.get(s)))(s));
|
|
68
|
-
/**
|
|
69
|
-
* Composes a Lens with an Optional, producing an Optional.
|
|
70
|
-
* Use when the next step in the focus is optional (may be absent).
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
* ```ts
|
|
74
|
-
* const userBioOpt = pipe(
|
|
75
|
-
* Lens.prop<User>()("profile"),
|
|
76
|
-
* Lens.andThenOptional(Optional.prop<Profile>()("bio")),
|
|
77
|
-
* );
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
Lens.andThenOptional = (inner) => (outer) => ({
|
|
81
|
-
get: (s) => inner.get(outer.get(s)),
|
|
82
|
-
set: (b) => (s) => outer.set(inner.set(b)(outer.get(s)))(s),
|
|
83
|
-
});
|
|
84
|
-
/**
|
|
85
|
-
* Converts a Lens to an Optional. Every Lens is a valid Optional
|
|
86
|
-
* whose get always returns Some.
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```ts
|
|
90
|
-
* pipe(
|
|
91
|
-
* Lens.prop<User>()("address"),
|
|
92
|
-
* Lens.toOptional,
|
|
93
|
-
* Optional.andThen(Optional.prop<Address>()("landmark")),
|
|
94
|
-
* );
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
Lens.toOptional = (lens) => ({
|
|
98
|
-
get: (s) => ({ kind: "Some", value: lens.get(s) }),
|
|
99
|
-
set: lens.set,
|
|
100
|
-
});
|
|
101
|
-
})(Lens || (exports.Lens = Lens = {}));
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Logged = void 0;
|
|
4
|
-
var Logged;
|
|
5
|
-
(function (Logged) {
|
|
6
|
-
/**
|
|
7
|
-
* Wraps a pure value into a `Logged` with an empty log.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* Logged.make<string, number>(42); // { value: 42, log: [] }
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
Logged.make = (value) => ({ value, log: [] });
|
|
15
|
-
/**
|
|
16
|
-
* Creates a `Logged` that records a single log entry and produces no
|
|
17
|
-
* meaningful value. Use this to append to the log inside a `chain`.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```ts
|
|
21
|
-
* Logged.tell("operation completed"); // { value: undefined, log: ["operation completed"] }
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
Logged.tell = (entry) => ({ value: undefined, log: [entry] });
|
|
25
|
-
/**
|
|
26
|
-
* Transforms the value inside a `Logged` without affecting the log.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* pipe(
|
|
31
|
-
* Logged.make<string, number>(5),
|
|
32
|
-
* Logged.map(n => n * 2),
|
|
33
|
-
* ); // { value: 10, log: [] }
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
Logged.map = (f) => (data) => ({
|
|
37
|
-
value: f(data.value),
|
|
38
|
-
log: data.log,
|
|
39
|
-
});
|
|
40
|
-
/**
|
|
41
|
-
* Sequences two `Logged` computations, concatenating their logs.
|
|
42
|
-
* The value from the first is passed to `f`; the resulting log entries are
|
|
43
|
-
* appended after the entries from the first.
|
|
44
|
-
*
|
|
45
|
-
* Data-last — the first computation is the data being piped.
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```ts
|
|
49
|
-
* const result = pipe(
|
|
50
|
-
* Logged.make<string, number>(1),
|
|
51
|
-
* Logged.chain(n => pipe(Logged.tell("step"), Logged.map(() => n + 1))),
|
|
52
|
-
* Logged.chain(n => pipe(Logged.tell("done"), Logged.map(() => n * 10))),
|
|
53
|
-
* );
|
|
54
|
-
*
|
|
55
|
-
* Logged.run(result); // [20, ["step", "done"]]
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
Logged.chain = (f) => (data) => {
|
|
59
|
-
const next = f(data.value);
|
|
60
|
-
return { value: next.value, log: [...data.log, ...next.log] };
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* Applies a function wrapped in a `Logged` to a value wrapped in a `Logged`,
|
|
64
|
-
* concatenating both logs.
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```ts
|
|
68
|
-
* const fn: Logged<string, (n: number) => number> = {
|
|
69
|
-
* value: n => n * 2,
|
|
70
|
-
* log: ["fn-loaded"],
|
|
71
|
-
* };
|
|
72
|
-
* const arg: Logged<string, number> = { value: 5, log: ["arg-loaded"] };
|
|
73
|
-
*
|
|
74
|
-
* const result = pipe(fn, Logged.ap(arg));
|
|
75
|
-
* Logged.run(result); // [10, ["fn-loaded", "arg-loaded"]]
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
Logged.ap = (arg) => (data) => ({
|
|
79
|
-
value: data.value(arg.value),
|
|
80
|
-
log: [...data.log, ...arg.log],
|
|
81
|
-
});
|
|
82
|
-
/**
|
|
83
|
-
* Runs a side effect on the value without changing the `Logged`.
|
|
84
|
-
* Useful for debugging or inspecting intermediate values.
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* ```ts
|
|
88
|
-
* pipe(
|
|
89
|
-
* Logged.make<string, number>(42),
|
|
90
|
-
* Logged.tap(n => console.log("value:", n)),
|
|
91
|
-
* );
|
|
92
|
-
* ```
|
|
93
|
-
*/
|
|
94
|
-
Logged.tap = (f) => (data) => {
|
|
95
|
-
f(data.value);
|
|
96
|
-
return data;
|
|
97
|
-
};
|
|
98
|
-
/**
|
|
99
|
-
* Extracts the value and log as a `readonly [A, ReadonlyArray<W>]` tuple.
|
|
100
|
-
* Use this at the boundary where you need to consume both.
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```ts
|
|
104
|
-
* const result = pipe(
|
|
105
|
-
* Logged.make<string, number>(1),
|
|
106
|
-
* Logged.chain(n => pipe(Logged.tell("incremented"), Logged.map(() => n + 1))),
|
|
107
|
-
* );
|
|
108
|
-
*
|
|
109
|
-
* const [value, log] = Logged.run(result);
|
|
110
|
-
* // value = 2, log = ["incremented"]
|
|
111
|
-
* ```
|
|
112
|
-
*/
|
|
113
|
-
Logged.run = (data) => [data.value, data.log];
|
|
114
|
-
})(Logged || (exports.Logged = Logged = {}));
|