@nlozgachev/pipelined 0.12.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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-Bd3gXPRQ.d.mts +677 -0
- package/dist/Task-BjAkkD6t.d.ts +677 -0
- package/dist/chunk-4TXC322E.mjs +136 -0
- package/dist/chunk-BYWKZLHM.mjs +10 -0
- package/dist/chunk-DBIC62UV.mjs +6 -0
- package/dist/chunk-FAZN3IWZ.mjs +554 -0
- package/dist/chunk-QPTGO5AS.mjs +150 -0
- package/dist/chunk-UV2HMF2A.mjs +514 -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 +58 -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 +42 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +1421 -0
- package/dist/index.mjs +120 -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 +10 -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 +18 -0
- package/package.json +64 -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
package/dist/utils.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,71 +1,66 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
"files": [
|
|
67
|
-
"esm",
|
|
68
|
-
"script",
|
|
69
|
-
"types"
|
|
70
|
-
]
|
|
2
|
+
"name": "@nlozgachev/pipelined",
|
|
3
|
+
"version": "0.14.0",
|
|
4
|
+
"description": "Simple functional programming toolkit for TypeScript",
|
|
5
|
+
"license": "BSD-3-Clause",
|
|
6
|
+
"homepage": "https://pipelined.lozgachev.dev",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/nlozgachev/pipelined.git"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"functional",
|
|
13
|
+
"fp",
|
|
14
|
+
"typescript",
|
|
15
|
+
"composition",
|
|
16
|
+
"pipe"
|
|
17
|
+
],
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=22"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"exports": {
|
|
27
|
+
"./composition": {
|
|
28
|
+
"types": "./dist/composition.d.ts",
|
|
29
|
+
"import": "./dist/composition.mjs",
|
|
30
|
+
"require": "./dist/composition.cjs"
|
|
31
|
+
},
|
|
32
|
+
"./core": {
|
|
33
|
+
"types": "./dist/core.d.ts",
|
|
34
|
+
"import": "./dist/core.mjs",
|
|
35
|
+
"require": "./dist/core.cjs"
|
|
36
|
+
},
|
|
37
|
+
"./utils": {
|
|
38
|
+
"types": "./dist/utils.d.ts",
|
|
39
|
+
"import": "./dist/utils.mjs",
|
|
40
|
+
"require": "./dist/utils.cjs"
|
|
41
|
+
},
|
|
42
|
+
"./types": {
|
|
43
|
+
"types": "./dist/types.d.ts",
|
|
44
|
+
"import": "./dist/types.mjs",
|
|
45
|
+
"require": "./dist/types.cjs"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"test": "vitest run",
|
|
50
|
+
"bench": "vitest bench",
|
|
51
|
+
"build": "tsup",
|
|
52
|
+
"format": "dprint fmt",
|
|
53
|
+
"format:check": "dprint check",
|
|
54
|
+
"typecheck": "tsc --noEmit",
|
|
55
|
+
"lint": "oxlint src/",
|
|
56
|
+
"publish:npm": "pnpm build && npm publish --access public"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@types/node": "25.5.0",
|
|
60
|
+
"dprint": "0.53.0",
|
|
61
|
+
"oxlint": "1.56.0",
|
|
62
|
+
"tsup": "8.5.1",
|
|
63
|
+
"typescript": "5.9.3",
|
|
64
|
+
"vitest": "4.1.0"
|
|
65
|
+
}
|
|
71
66
|
}
|
package/esm/mod.js
DELETED
package/esm/package.json
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts a multi-argument function into a curried function.
|
|
3
|
-
* The inverse of `uncurry`.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* const add = (a: number, b: number) => a + b;
|
|
8
|
-
* const curriedAdd = curry(add);
|
|
9
|
-
* curriedAdd(1)(2); // 3
|
|
10
|
-
*
|
|
11
|
-
* // Partial application
|
|
12
|
-
* const addTen = curriedAdd(10);
|
|
13
|
-
* addTen(5); // 15
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* @see {@link uncurry} for the inverse operation
|
|
17
|
-
* @see {@link curry3} for 3-argument functions
|
|
18
|
-
* @see {@link curry4} for 4-argument functions
|
|
19
|
-
*/
|
|
20
|
-
export const curry = (f) => (a) => (b) => f(a, b);
|
|
21
|
-
/**
|
|
22
|
-
* Converts a 3-argument function into a curried function.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* const add3 = (a: number, b: number, c: number) => a + b + c;
|
|
27
|
-
* const curriedAdd3 = curry3(add3);
|
|
28
|
-
* curriedAdd3(1)(2)(3); // 6
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export const curry3 = (f) => (a) => (b) => (c) => f(a, b, c);
|
|
32
|
-
/**
|
|
33
|
-
* Converts a 4-argument function into a curried function.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```ts
|
|
37
|
-
* const add4 = (a: number, b: number, c: number, d: number) => a + b + c + d;
|
|
38
|
-
* const curriedAdd4 = curry4(add4);
|
|
39
|
-
* curriedAdd4(1)(2)(3)(4); // 10
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
export const curry4 = (f) => (a) => (b) => (c) => (d) => f(a, b, c, d);
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flips the order of arguments for a curried binary function.
|
|
3
|
-
* Converts a data-last function to data-first.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* // Original data-last (for pipe)
|
|
8
|
-
* pipe(
|
|
9
|
-
* Option.some(5),
|
|
10
|
-
* Option.map(n => n * 2)
|
|
11
|
-
* ); // Some(10)
|
|
12
|
-
*
|
|
13
|
-
* // Flipped to data-first
|
|
14
|
-
* const mapFirst = flip(Option.map);
|
|
15
|
-
* mapFirst(Option.some(5))(n => n * 2); // Some(10)
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* @see {@link uncurry} for converting curried functions to multi-argument functions
|
|
19
|
-
*/
|
|
20
|
-
export const flip = (f) => (b) => (a) => f(a)(b);
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns the value unchanged. The identity function.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* ```ts
|
|
6
|
-
* identity(42); // 42
|
|
7
|
-
* pipe(Option.some(5), Option.fold(() => 0, identity)); // 5
|
|
8
|
-
* ```
|
|
9
|
-
*/
|
|
10
|
-
export const identity = (a) => a;
|
|
11
|
-
/**
|
|
12
|
-
* Creates a function that always returns the given value, ignoring its argument.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* const always42 = constant(42);
|
|
17
|
-
* always42(); // 42
|
|
18
|
-
* [1, 2, 3].map(constant("x")); // ["x", "x", "x"]
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export const constant = (a) => () => a;
|
|
22
|
-
/** Always returns `true`. */
|
|
23
|
-
export const constTrue = () => true;
|
|
24
|
-
/** Always returns `false`. */
|
|
25
|
-
export const constFalse = () => false;
|
|
26
|
-
/** Always returns `null`. */
|
|
27
|
-
export const constNull = () => null;
|
|
28
|
-
/** Always returns `undefined`. */
|
|
29
|
-
export const constUndefined = () => undefined;
|
|
30
|
-
/** Always returns `void`. */
|
|
31
|
-
export const constVoid = () => { };
|
|
32
|
-
/**
|
|
33
|
-
* Combines two predicates with logical AND.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```ts
|
|
37
|
-
* const isPositive = (n: number) => n > 0;
|
|
38
|
-
* const isEven = (n: number) => n % 2 === 0;
|
|
39
|
-
* const isPositiveEven = and(isPositive, isEven);
|
|
40
|
-
*
|
|
41
|
-
* isPositiveEven(4); // true
|
|
42
|
-
* isPositiveEven(-2); // false
|
|
43
|
-
* isPositiveEven(3); // false
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
export const and = (p1, p2) => (...args) => p1(...args) && p2(...args);
|
|
47
|
-
/**
|
|
48
|
-
* Combines two predicates with logical OR.
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```ts
|
|
52
|
-
* const isNegative = (n: number) => n < 0;
|
|
53
|
-
* const isZero = (n: number) => n === 0;
|
|
54
|
-
* const isNonPositive = or(isNegative, isZero);
|
|
55
|
-
*
|
|
56
|
-
* isNonPositive(-1); // true
|
|
57
|
-
* isNonPositive(0); // true
|
|
58
|
-
* isNonPositive(1); // false
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
export const or = (p1, p2) => (...args) => p1(...args) || p2(...args);
|
|
62
|
-
/**
|
|
63
|
-
* Creates a function that executes at most once.
|
|
64
|
-
* Subsequent calls return the cached result from the first execution.
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```ts
|
|
68
|
-
* let count = 0;
|
|
69
|
-
* const initOnce = once(() => { count++; return "initialized"; });
|
|
70
|
-
*
|
|
71
|
-
* initOnce(); // "initialized", count === 1
|
|
72
|
-
* initOnce(); // "initialized", count === 1 (not called again)
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
export const once = (f) => {
|
|
76
|
-
let called = false;
|
|
77
|
-
let result;
|
|
78
|
-
return () => {
|
|
79
|
-
if (!called) {
|
|
80
|
-
result = f();
|
|
81
|
-
called = true;
|
|
82
|
-
}
|
|
83
|
-
return result;
|
|
84
|
-
};
|
|
85
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export * from "./compose.js";
|
|
2
|
-
export * from "./converge.js";
|
|
3
|
-
export * from "./curry.js";
|
|
4
|
-
export * from "./flip.js";
|
|
5
|
-
export * from "./fn.js";
|
|
6
|
-
export * from "./flow.js";
|
|
7
|
-
export * from "./juxt.js";
|
|
8
|
-
export * from "./memoize.js";
|
|
9
|
-
export * from "./not.js";
|
|
10
|
-
export * from "./on.js";
|
|
11
|
-
export * from "./pipe.js";
|
|
12
|
-
export * from "./tap.js";
|
|
13
|
-
export * from "./uncurry.js";
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates a memoized version of a function that caches results.
|
|
3
|
-
* Subsequent calls with the same argument return the cached result.
|
|
4
|
-
*
|
|
5
|
-
* By default, uses the argument directly as the cache key.
|
|
6
|
-
* For complex arguments, provide a custom `keyFn` to generate cache keys.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* // Basic usage
|
|
11
|
-
* const expensive = memoize((n: number) => {
|
|
12
|
-
* console.log("Computing...");
|
|
13
|
-
* return n * 2;
|
|
14
|
-
* });
|
|
15
|
-
*
|
|
16
|
-
* expensive(5); // logs "Computing...", returns 10
|
|
17
|
-
* expensive(5); // returns 10 (cached, no log)
|
|
18
|
-
* expensive(3); // logs "Computing...", returns 6
|
|
19
|
-
*
|
|
20
|
-
* // With custom key function for objects
|
|
21
|
-
* const fetchUser = memoize(
|
|
22
|
-
* (opts: { id: string }) => fetch(`/users/${opts.id}`),
|
|
23
|
-
* opts => opts.id
|
|
24
|
-
* );
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
export const memoize = (f, keyFn = (a) => a) => {
|
|
28
|
-
const cache = new Map();
|
|
29
|
-
return (a) => {
|
|
30
|
-
const key = keyFn(a);
|
|
31
|
-
if (cache.has(key)) {
|
|
32
|
-
return cache.get(key);
|
|
33
|
-
}
|
|
34
|
-
const result = f(a);
|
|
35
|
-
cache.set(key, result);
|
|
36
|
-
return result;
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* Creates a memoized version of a function using WeakMap.
|
|
41
|
-
* Only works with object arguments, but allows garbage collection
|
|
42
|
-
* of cached values when keys are no longer referenced.
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```ts
|
|
46
|
-
* const processUser = memoizeWeak((user: User) => {
|
|
47
|
-
* return expensiveOperation(user);
|
|
48
|
-
* });
|
|
49
|
-
*
|
|
50
|
-
* const user = { id: 1, name: "Alice" };
|
|
51
|
-
* processUser(user); // computed
|
|
52
|
-
* processUser(user); // cached
|
|
53
|
-
* // When `user` is garbage collected, cached result is too
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
export const memoizeWeak = (f) => {
|
|
57
|
-
const cache = new WeakMap();
|
|
58
|
-
return (a) => {
|
|
59
|
-
if (cache.has(a)) {
|
|
60
|
-
return cache.get(a);
|
|
61
|
-
}
|
|
62
|
-
const result = f(a);
|
|
63
|
-
cache.set(a, result);
|
|
64
|
-
return result;
|
|
65
|
-
};
|
|
66
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Negates a predicate function.
|
|
3
|
-
* Returns a new predicate that returns true when the original returns false, and vice versa.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* const isEven = (n: number) => n % 2 === 0;
|
|
8
|
-
* const isOdd = not(isEven);
|
|
9
|
-
*
|
|
10
|
-
* isOdd(3); // true
|
|
11
|
-
* isOdd(4); // false
|
|
12
|
-
*
|
|
13
|
-
* // With array methods
|
|
14
|
-
* const numbers = [1, 2, 3, 4, 5];
|
|
15
|
-
* numbers.filter(not(isEven)); // [1, 3, 5]
|
|
16
|
-
*
|
|
17
|
-
* // In pipelines
|
|
18
|
-
* pipe(
|
|
19
|
-
* users,
|
|
20
|
-
* Array.filter(not(isAdmin)),
|
|
21
|
-
* Array.map(u => u.name)
|
|
22
|
-
* );
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export const not = (predicate) => (...args) => !predicate(...args);
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Applies a projection to both arguments of a binary function before calling it.
|
|
3
|
-
* Most useful for building comparators and equality checks over projected values.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* const byLength = on((a: number, b: number) => a - b, (s: string) => s.length);
|
|
8
|
-
*
|
|
9
|
-
* ["banana", "fig", "apple"].sort(byLength); // ["fig", "apple", "banana"]
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
export const on = (f, g) => (a, b) => f(g(a), g(b));
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Executes a side effect function and returns the original value unchanged.
|
|
3
|
-
* Useful for logging, debugging, or other side effects within a pipeline.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* // Debugging a pipeline
|
|
8
|
-
* pipe(
|
|
9
|
-
* Option.some(5),
|
|
10
|
-
* tap(x => console.log("Before map:", x)),
|
|
11
|
-
* Option.map(n => n * 2),
|
|
12
|
-
* tap(x => console.log("After map:", x)),
|
|
13
|
-
* Option.getOrElse(0)
|
|
14
|
-
* );
|
|
15
|
-
* // logs: "Before map: { kind: 'Some', value: 5 }"
|
|
16
|
-
* // logs: "After map: { kind: 'Some', value: 10 }"
|
|
17
|
-
* // returns: 10
|
|
18
|
-
*
|
|
19
|
-
* // Collecting intermediate values
|
|
20
|
-
* const values: number[] = [];
|
|
21
|
-
* pipe(
|
|
22
|
-
* [1, 2, 3],
|
|
23
|
-
* arr => arr.map(n => n * 2),
|
|
24
|
-
* tap(arr => values.push(...arr))
|
|
25
|
-
* );
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* @see {@link Option.tap} for Option-specific tap that only runs on Some
|
|
29
|
-
*/
|
|
30
|
-
export const tap = (f) => (a) => {
|
|
31
|
-
f(a);
|
|
32
|
-
return a;
|
|
33
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// deno-lint-ignore no-explicit-any
|
|
2
|
-
export function uncurry(f) {
|
|
3
|
-
// f.length determines the outer arity; inner.length determines the inner arity.
|
|
4
|
-
// The typed overloads guarantee these are 0, 1, or 2 total args.
|
|
5
|
-
// deno-lint-ignore no-explicit-any
|
|
6
|
-
return (...args) => {
|
|
7
|
-
const inner = f(...args.slice(0, f.length));
|
|
8
|
-
return inner.length === 0 ? inner() : inner(...args.slice(f.length));
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Converts a curried 3-argument function into a multi-argument function.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* const curriedAdd3 = (a: number) => (b: number) => (c: number) => a + b + c;
|
|
17
|
-
* const add3 = uncurry3(curriedAdd3);
|
|
18
|
-
* add3(1, 2, 3); // 6
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export const uncurry3 = (f) => (a, b, c) => f(a)(b)(c);
|
|
22
|
-
/**
|
|
23
|
-
* Converts a curried 4-argument function into a multi-argument function.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* const curriedAdd4 = (a: number) => (b: number) => (c: number) => (d: number) => a + b + c + d;
|
|
28
|
-
* const add4 = uncurry4(curriedAdd4);
|
|
29
|
-
* add4(1, 2, 3, 4); // 10
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
export const uncurry4 = (f) => (a, b, c, d) => f(a)(b)(c)(d);
|
package/esm/src/Core/Deferred.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const _store = new WeakMap();
|
|
2
|
-
export var Deferred;
|
|
3
|
-
(function (Deferred) {
|
|
4
|
-
/**
|
|
5
|
-
* Wraps a `Promise` into a `Deferred`, structurally excluding rejection handlers,
|
|
6
|
-
* `.catch()`, `.finally()`, and chainable `.then()`.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* const d = Deferred.fromPromise(Promise.resolve("hello"));
|
|
11
|
-
* const value = await d; // "hello"
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
Deferred.fromPromise = (p) => {
|
|
15
|
-
const d = ({ then: ((f) => p.then(f)) });
|
|
16
|
-
_store.set(d, p);
|
|
17
|
-
return d;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Converts a `Deferred` back into a `Promise`.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```ts
|
|
24
|
-
* const p = Deferred.toPromise(Deferred.fromPromise(Promise.resolve(42)));
|
|
25
|
-
* // p is Promise<42>
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
Deferred.toPromise = (d) => _store.get(d) ??
|
|
29
|
-
new Promise((resolve) => d.then(resolve));
|
|
30
|
-
})(Deferred || (Deferred = {}));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/esm/src/Core/Lens.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
export var Lens;
|
|
2
|
-
(function (Lens) {
|
|
3
|
-
/**
|
|
4
|
-
* Constructs a Lens from a getter and a setter.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* const nameLens = Lens.make(
|
|
9
|
-
* (user: User) => user.name,
|
|
10
|
-
* (name) => (user) => ({ ...user, name }),
|
|
11
|
-
* );
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
Lens.make = (get, set) => ({ get, set });
|
|
15
|
-
/**
|
|
16
|
-
* Creates a Lens that focuses on a property of an object.
|
|
17
|
-
* Call with the structure type first, then the key.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```ts
|
|
21
|
-
* const nameLens = Lens.prop<User>()("name");
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
Lens.prop = () => (key) => Lens.make((s) => s[key], (a) => (s) => ({ ...s, [key]: a }));
|
|
25
|
-
/**
|
|
26
|
-
* Reads the focused value from a structure.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* pipe(user, Lens.get(nameLens)); // "Alice"
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
Lens.get = (lens) => (s) => lens.get(s);
|
|
34
|
-
/**
|
|
35
|
-
* Replaces the focused value within a structure, returning a new structure.
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```ts
|
|
39
|
-
* pipe(user, Lens.set(nameLens)("Bob")); // new User with name "Bob"
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
Lens.set = (lens) => (a) => (s) => lens.set(a)(s);
|
|
43
|
-
/**
|
|
44
|
-
* Applies a function to the focused value, returning a new structure.
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```ts
|
|
48
|
-
* pipe(user, Lens.modify(nameLens)(n => n.toUpperCase())); // "ALICE"
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
Lens.modify = (lens) => (f) => (s) => lens.set(f(lens.get(s)))(s);
|
|
52
|
-
/**
|
|
53
|
-
* Composes two Lenses: focuses through the outer, then through the inner.
|
|
54
|
-
* Use in a pipe chain to build up a deep focus step by step.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* ```ts
|
|
58
|
-
* const userCityLens = pipe(
|
|
59
|
-
* Lens.prop<User>()("address"),
|
|
60
|
-
* Lens.andThen(Lens.prop<Address>()("city")),
|
|
61
|
-
* );
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
Lens.andThen = (inner) => (outer) => Lens.make((s) => inner.get(outer.get(s)), (b) => (s) => outer.set(inner.set(b)(outer.get(s)))(s));
|
|
65
|
-
/**
|
|
66
|
-
* Composes a Lens with an Optional, producing an Optional.
|
|
67
|
-
* Use when the next step in the focus is optional (may be absent).
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```ts
|
|
71
|
-
* const userBioOpt = pipe(
|
|
72
|
-
* Lens.prop<User>()("profile"),
|
|
73
|
-
* Lens.andThenOptional(Optional.prop<Profile>()("bio")),
|
|
74
|
-
* );
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
Lens.andThenOptional = (inner) => (outer) => ({
|
|
78
|
-
get: (s) => inner.get(outer.get(s)),
|
|
79
|
-
set: (b) => (s) => outer.set(inner.set(b)(outer.get(s)))(s),
|
|
80
|
-
});
|
|
81
|
-
/**
|
|
82
|
-
* Converts a Lens to an Optional. Every Lens is a valid Optional
|
|
83
|
-
* whose get always returns Some.
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* ```ts
|
|
87
|
-
* pipe(
|
|
88
|
-
* Lens.prop<User>()("address"),
|
|
89
|
-
* Lens.toOptional,
|
|
90
|
-
* Optional.andThen(Optional.prop<Address>()("landmark")),
|
|
91
|
-
* );
|
|
92
|
-
* ```
|
|
93
|
-
*/
|
|
94
|
-
Lens.toOptional = (lens) => ({
|
|
95
|
-
get: (s) => ({ kind: "Some", value: lens.get(s) }),
|
|
96
|
-
set: lens.set,
|
|
97
|
-
});
|
|
98
|
-
})(Lens || (Lens = {}));
|