@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
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composes functions from right to left, returning a new function.
|
|
3
|
+
* This is the traditional mathematical function composition: (f . g)(x) = f(g(x))
|
|
4
|
+
*
|
|
5
|
+
* Unlike `flow` which reads left-to-right, `compose` reads right-to-left,
|
|
6
|
+
* matching how nested function calls would be written.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const addOne = (n: number) => n + 1;
|
|
11
|
+
* const double = (n: number) => n * 2;
|
|
12
|
+
*
|
|
13
|
+
* // compose: right-to-left (double first, then addOne)
|
|
14
|
+
* const composed = compose(addOne, double);
|
|
15
|
+
* composed(5); // 11 (5 * 2 + 1)
|
|
16
|
+
*
|
|
17
|
+
* // flow: left-to-right (addOne first, then double)
|
|
18
|
+
* const flowed = flow(addOne, double);
|
|
19
|
+
* flowed(5); // 12 ((5 + 1) * 2)
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @see {@link flow} for left-to-right composition
|
|
23
|
+
*/
|
|
24
|
+
declare function compose<A, B>(ab: (a: A) => B): (a: A) => B;
|
|
25
|
+
declare function compose<A, B, C>(bc: (b: B) => C, ab: (a: A) => B): (a: A) => C;
|
|
26
|
+
declare function compose<A, B, C, D>(cd: (c: C) => D, bc: (b: B) => C, ab: (a: A) => B): (a: A) => D;
|
|
27
|
+
declare function compose<A, B, C, D, E>(de: (d: D) => E, cd: (c: C) => D, bc: (b: B) => C, ab: (a: A) => B): (a: A) => E;
|
|
28
|
+
declare function compose<A, B, C, D, E, F>(ef: (e: E) => F, de: (d: D) => E, cd: (c: C) => D, bc: (b: B) => C, ab: (a: A) => B): (a: A) => F;
|
|
29
|
+
declare function compose<A, B, C, D, E, F, G>(fg: (f: F) => G, ef: (e: E) => F, de: (d: D) => E, cd: (c: C) => D, bc: (b: B) => C, ab: (a: A) => B): (a: A) => G;
|
|
30
|
+
declare function compose<A, B, C, D, E, F, G, H>(gh: (g: G) => H, fg: (f: F) => G, ef: (e: E) => F, de: (d: D) => E, cd: (c: C) => D, bc: (b: B) => C, ab: (a: A) => B): (a: A) => H;
|
|
31
|
+
declare function compose<A, B, C, D, E, F, G, H, I>(hi: (h: H) => I, gh: (g: G) => H, fg: (f: F) => G, ef: (e: E) => F, de: (d: D) => E, cd: (c: C) => D, bc: (b: B) => C, ab: (a: A) => B): (a: A) => I;
|
|
32
|
+
declare function compose<A, B, C, D, E, F, G, H, I, J>(ij: (i: I) => J, hi: (h: H) => I, gh: (g: G) => H, fg: (f: F) => G, ef: (e: E) => F, de: (d: D) => E, cd: (c: C) => D, bc: (b: B) => C, ab: (a: A) => B): (a: A) => J;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Applies an input to several transformer functions independently, then passes all results to a
|
|
36
|
+
* combining function.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const toNameRecord = converge(
|
|
41
|
+
* (trimmed: string, initials: string) => ({ trimmed, initials }),
|
|
42
|
+
* [
|
|
43
|
+
* (name: string) => name.trim(),
|
|
44
|
+
* (name: string) => name.split(" ").map((w) => w[0]).join(""),
|
|
45
|
+
* ],
|
|
46
|
+
* );
|
|
47
|
+
*
|
|
48
|
+
* toNameRecord(" Alice Bob "); // { trimmed: "Alice Bob", initials: "AB" }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
declare function converge<A, B, C, R>(f: (b: B, c: C) => R, transformers: [(a: A) => B, (a: A) => C]): (a: A) => R;
|
|
52
|
+
declare function converge<A, B, C, D, R>(f: (b: B, c: C, d: D) => R, transformers: [(a: A) => B, (a: A) => C, (a: A) => D]): (a: A) => R;
|
|
53
|
+
declare function converge<A, B, C, D, E, R>(f: (b: B, c: C, d: D, e: E) => R, transformers: [(a: A) => B, (a: A) => C, (a: A) => D, (a: A) => E]): (a: A) => R;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Converts a multi-argument function into a curried function.
|
|
57
|
+
* The inverse of `uncurry`.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* const add = (a: number, b: number) => a + b;
|
|
62
|
+
* const curriedAdd = curry(add);
|
|
63
|
+
* curriedAdd(1)(2); // 3
|
|
64
|
+
*
|
|
65
|
+
* // Partial application
|
|
66
|
+
* const addTen = curriedAdd(10);
|
|
67
|
+
* addTen(5); // 15
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @see {@link uncurry} for the inverse operation
|
|
71
|
+
* @see {@link curry3} for 3-argument functions
|
|
72
|
+
* @see {@link curry4} for 4-argument functions
|
|
73
|
+
*/
|
|
74
|
+
declare const curry: <A, B, C>(f: (a: A, b: B) => C) => (a: A) => (b: B) => C;
|
|
75
|
+
/**
|
|
76
|
+
* Converts a 3-argument function into a curried function.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* const add3 = (a: number, b: number, c: number) => a + b + c;
|
|
81
|
+
* const curriedAdd3 = curry3(add3);
|
|
82
|
+
* curriedAdd3(1)(2)(3); // 6
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
declare const curry3: <A, B, C, D>(f: (a: A, b: B, c: C) => D) => (a: A) => (b: B) => (c: C) => D;
|
|
86
|
+
/**
|
|
87
|
+
* Converts a 4-argument function into a curried function.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* const add4 = (a: number, b: number, c: number, d: number) => a + b + c + d;
|
|
92
|
+
* const curriedAdd4 = curry4(add4);
|
|
93
|
+
* curriedAdd4(1)(2)(3)(4); // 10
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
declare const curry4: <A, B, C, D, E>(f: (a: A, b: B, c: C, d: D) => E) => (a: A) => (b: B) => (c: C) => (d: D) => E;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Flips the order of arguments for a curried binary function.
|
|
100
|
+
* Converts a data-last function to data-first.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* // Original data-last (for pipe)
|
|
105
|
+
* pipe(
|
|
106
|
+
* Option.some(5),
|
|
107
|
+
* Option.map(n => n * 2)
|
|
108
|
+
* ); // Some(10)
|
|
109
|
+
*
|
|
110
|
+
* // Flipped to data-first
|
|
111
|
+
* const mapFirst = flip(Option.map);
|
|
112
|
+
* mapFirst(Option.some(5))(n => n * 2); // Some(10)
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @see {@link uncurry} for converting curried functions to multi-argument functions
|
|
116
|
+
*/
|
|
117
|
+
declare const flip: <A, B, C>(f: (a: A) => (b: B) => C) => (b: B) => (a: A) => C;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Composes functions from left to right, returning a new function.
|
|
121
|
+
* Unlike `pipe`, `flow` doesn't take an initial value - it creates
|
|
122
|
+
* a reusable pipeline that can be called later with arguments.
|
|
123
|
+
*
|
|
124
|
+
* Use `flow` when you want to create a named, reusable transformation.
|
|
125
|
+
* Use `pipe` when you want to immediately transform a value.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* // Create a reusable transformation
|
|
130
|
+
* const processUser = flow(
|
|
131
|
+
* (user: User) => user.name,
|
|
132
|
+
* name => name.toUpperCase(),
|
|
133
|
+
* name => `Hello, ${name}!`
|
|
134
|
+
* );
|
|
135
|
+
*
|
|
136
|
+
* processUser({ name: "Alice" }); // "Hello, ALICE!"
|
|
137
|
+
* processUser({ name: "Bob" }); // "Hello, BOB!"
|
|
138
|
+
*
|
|
139
|
+
* // Compare with pipe (one-time use):
|
|
140
|
+
* pipe(
|
|
141
|
+
* user,
|
|
142
|
+
* u => u.name,
|
|
143
|
+
* name => name.toUpperCase()
|
|
144
|
+
* );
|
|
145
|
+
*
|
|
146
|
+
* // flow creates a function, pipe applies immediately:
|
|
147
|
+
* const double = flow((n: number) => n * 2);
|
|
148
|
+
* double(5); // 10
|
|
149
|
+
*
|
|
150
|
+
* pipe(5, n => n * 2); // 10 (immediate result)
|
|
151
|
+
* ```
|
|
152
|
+
*
|
|
153
|
+
* @see {@link pipe} for immediate value transformation
|
|
154
|
+
*/
|
|
155
|
+
declare function flow<A extends ReadonlyArray<unknown>, B>(ab: (...a: A) => B): (...a: A) => B;
|
|
156
|
+
declare function flow<A extends ReadonlyArray<unknown>, B, C>(ab: (...a: A) => B, bc: (b: B) => C): (...a: A) => C;
|
|
157
|
+
declare function flow<A extends ReadonlyArray<unknown>, B, C, D>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...a: A) => D;
|
|
158
|
+
declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E): (...a: A) => E;
|
|
159
|
+
declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E, F>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F): (...a: A) => F;
|
|
160
|
+
declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E, F, G>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G): (...a: A) => G;
|
|
161
|
+
declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E, F, G, H>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H): (...a: A) => H;
|
|
162
|
+
declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E, F, G, H, I>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I): (...a: A) => I;
|
|
163
|
+
declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E, F, G, H, I, J>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J): (...a: A) => J;
|
|
164
|
+
declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E, F, G, H, I, J, K>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K): (...a: A) => K;
|
|
165
|
+
declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E, F, G, H, I, J, K, L>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L): (...a: A) => L;
|
|
166
|
+
declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E, F, G, H, I, J, K, L, M>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M): (...a: A) => M;
|
|
167
|
+
declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E, F, G, H, I, J, K, L, M, N>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N): (...a: A) => N;
|
|
168
|
+
declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O): (...a: A) => O;
|
|
169
|
+
declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P): (...a: A) => P;
|
|
170
|
+
declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Q): (...a: A) => Q;
|
|
171
|
+
declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Q, qr: (q: Q) => R): (...a: A) => R;
|
|
172
|
+
declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Q, qr: (q: Q) => R, rs: (r: R) => S): (...a: A) => S;
|
|
173
|
+
declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Q, qr: (q: Q) => R, rs: (r: R) => S, st: (s: S) => T): (...a: A) => T;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Returns the value unchanged. The identity function.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* identity(42); // 42
|
|
181
|
+
* pipe(Option.some(5), Option.fold(() => 0, identity)); // 5
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
declare const identity: <A>(a: A) => A;
|
|
185
|
+
/**
|
|
186
|
+
* Creates a function that always returns the given value, ignoring its argument.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* const always42 = constant(42);
|
|
191
|
+
* always42(); // 42
|
|
192
|
+
* [1, 2, 3].map(constant("x")); // ["x", "x", "x"]
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
declare const constant: <A>(a: A) => () => A;
|
|
196
|
+
/** Always returns `true`. */
|
|
197
|
+
declare const constTrue: () => true;
|
|
198
|
+
/** Always returns `false`. */
|
|
199
|
+
declare const constFalse: () => false;
|
|
200
|
+
/** Always returns `null`. */
|
|
201
|
+
declare const constNull: () => null;
|
|
202
|
+
/** Always returns `undefined`. */
|
|
203
|
+
declare const constUndefined: () => undefined;
|
|
204
|
+
/** Always returns `void`. */
|
|
205
|
+
declare const constVoid: () => void;
|
|
206
|
+
/**
|
|
207
|
+
* Combines two predicates with logical AND.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```ts
|
|
211
|
+
* const isPositive = (n: number) => n > 0;
|
|
212
|
+
* const isEven = (n: number) => n % 2 === 0;
|
|
213
|
+
* const isPositiveEven = and(isPositive, isEven);
|
|
214
|
+
*
|
|
215
|
+
* isPositiveEven(4); // true
|
|
216
|
+
* isPositiveEven(-2); // false
|
|
217
|
+
* isPositiveEven(3); // false
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
declare const and: <A extends ReadonlyArray<unknown>>(p1: (...args: A) => boolean, p2: (...args: A) => boolean) => (...args: A) => boolean;
|
|
221
|
+
/**
|
|
222
|
+
* Combines two predicates with logical OR.
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```ts
|
|
226
|
+
* const isNegative = (n: number) => n < 0;
|
|
227
|
+
* const isZero = (n: number) => n === 0;
|
|
228
|
+
* const isNonPositive = or(isNegative, isZero);
|
|
229
|
+
*
|
|
230
|
+
* isNonPositive(-1); // true
|
|
231
|
+
* isNonPositive(0); // true
|
|
232
|
+
* isNonPositive(1); // false
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
declare const or: <A extends ReadonlyArray<unknown>>(p1: (...args: A) => boolean, p2: (...args: A) => boolean) => (...args: A) => boolean;
|
|
236
|
+
/**
|
|
237
|
+
* Creates a function that executes at most once.
|
|
238
|
+
* Subsequent calls return the cached result from the first execution.
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```ts
|
|
242
|
+
* let count = 0;
|
|
243
|
+
* const initOnce = once(() => { count++; return "initialized"; });
|
|
244
|
+
*
|
|
245
|
+
* initOnce(); // "initialized", count === 1
|
|
246
|
+
* initOnce(); // "initialized", count === 1 (not called again)
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
declare const once: <A>(f: () => A) => () => A;
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Applies an input to an array of functions and collects the results into a tuple.
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```ts
|
|
256
|
+
* const nameParts = juxt([
|
|
257
|
+
* (name: string) => name.split(" ")[0],
|
|
258
|
+
* (name: string) => name.split(" ").slice(1).join(" "),
|
|
259
|
+
* ]);
|
|
260
|
+
*
|
|
261
|
+
* nameParts("Alice Smith"); // ["Alice", "Smith"]
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
264
|
+
declare function juxt<A, B, C>(fns: [(a: A) => B, (a: A) => C]): (a: A) => [B, C];
|
|
265
|
+
declare function juxt<A, B, C, D>(fns: [(a: A) => B, (a: A) => C, (a: A) => D]): (a: A) => [B, C, D];
|
|
266
|
+
declare function juxt<A, B, C, D, E>(fns: [(a: A) => B, (a: A) => C, (a: A) => D, (a: A) => E]): (a: A) => [B, C, D, E];
|
|
267
|
+
declare function juxt<A, B>(fns: ReadonlyArray<(a: A) => B>): (a: A) => B[];
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Creates a memoized version of a function that caches results.
|
|
271
|
+
* Subsequent calls with the same argument return the cached result.
|
|
272
|
+
*
|
|
273
|
+
* By default, uses the argument directly as the cache key.
|
|
274
|
+
* For complex arguments, provide a custom `keyFn` to generate cache keys.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```ts
|
|
278
|
+
* // Basic usage
|
|
279
|
+
* const expensive = memoize((n: number) => {
|
|
280
|
+
* console.log("Computing...");
|
|
281
|
+
* return n * 2;
|
|
282
|
+
* });
|
|
283
|
+
*
|
|
284
|
+
* expensive(5); // logs "Computing...", returns 10
|
|
285
|
+
* expensive(5); // returns 10 (cached, no log)
|
|
286
|
+
* expensive(3); // logs "Computing...", returns 6
|
|
287
|
+
*
|
|
288
|
+
* // With custom key function for objects
|
|
289
|
+
* const fetchUser = memoize(
|
|
290
|
+
* (opts: { id: string }) => fetch(`/users/${opts.id}`),
|
|
291
|
+
* opts => opts.id
|
|
292
|
+
* );
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
declare const memoize: <A, B>(f: (a: A) => B, keyFn?: (a: A) => unknown) => (a: A) => B;
|
|
296
|
+
/**
|
|
297
|
+
* Creates a memoized version of a function using WeakMap.
|
|
298
|
+
* Only works with object arguments, but allows garbage collection
|
|
299
|
+
* of cached values when keys are no longer referenced.
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```ts
|
|
303
|
+
* const processUser = memoizeWeak((user: User) => {
|
|
304
|
+
* return expensiveOperation(user);
|
|
305
|
+
* });
|
|
306
|
+
*
|
|
307
|
+
* const user = { id: 1, name: "Alice" };
|
|
308
|
+
* processUser(user); // computed
|
|
309
|
+
* processUser(user); // cached
|
|
310
|
+
* // When `user` is garbage collected, cached result is too
|
|
311
|
+
* ```
|
|
312
|
+
*/
|
|
313
|
+
declare const memoizeWeak: <A extends object, B>(f: (a: A) => B) => (a: A) => B;
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Negates a predicate function.
|
|
317
|
+
* Returns a new predicate that returns true when the original returns false, and vice versa.
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* ```ts
|
|
321
|
+
* const isEven = (n: number) => n % 2 === 0;
|
|
322
|
+
* const isOdd = not(isEven);
|
|
323
|
+
*
|
|
324
|
+
* isOdd(3); // true
|
|
325
|
+
* isOdd(4); // false
|
|
326
|
+
*
|
|
327
|
+
* // With array methods
|
|
328
|
+
* const numbers = [1, 2, 3, 4, 5];
|
|
329
|
+
* numbers.filter(not(isEven)); // [1, 3, 5]
|
|
330
|
+
*
|
|
331
|
+
* // In pipelines
|
|
332
|
+
* pipe(
|
|
333
|
+
* users,
|
|
334
|
+
* Array.filter(not(isAdmin)),
|
|
335
|
+
* Array.map(u => u.name)
|
|
336
|
+
* );
|
|
337
|
+
* ```
|
|
338
|
+
*/
|
|
339
|
+
declare const not: <A extends ReadonlyArray<unknown>>(predicate: (...args: A) => boolean) => (...args: A) => boolean;
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Applies a projection to both arguments of a binary function before calling it.
|
|
343
|
+
* Most useful for building comparators and equality checks over projected values.
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* ```ts
|
|
347
|
+
* const byLength = on((a: number, b: number) => a - b, (s: string) => s.length);
|
|
348
|
+
*
|
|
349
|
+
* ["banana", "fig", "apple"].sort(byLength); // ["fig", "apple", "banana"]
|
|
350
|
+
* ```
|
|
351
|
+
*/
|
|
352
|
+
declare const on: <A, B, C>(f: (b1: B, b2: B) => C, g: (a: A) => B) => (a: A, b: A) => C;
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Pipes a value through a series of functions from left to right.
|
|
356
|
+
* Each function receives the output of the previous function.
|
|
357
|
+
*
|
|
358
|
+
* `pipe` is the primary way to compose operations in this library.
|
|
359
|
+
* It makes code read top-to-bottom, left-to-right, which is more
|
|
360
|
+
* intuitive for developers coming from imperative backgrounds.
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* ```ts
|
|
364
|
+
* // Basic usage
|
|
365
|
+
* const result = pipe(
|
|
366
|
+
* 5,
|
|
367
|
+
* n => n * 2,
|
|
368
|
+
* n => n + 1
|
|
369
|
+
* ); // 11
|
|
370
|
+
*
|
|
371
|
+
* // With library functions
|
|
372
|
+
* const greeting = pipe(
|
|
373
|
+
* Option.some("Alice"),
|
|
374
|
+
* Option.map(name => name.toUpperCase()),
|
|
375
|
+
* Option.map(name => `Hello, ${name}!`),
|
|
376
|
+
* Option.getOrElse("Hello!")
|
|
377
|
+
* ); // "Hello, ALICE!"
|
|
378
|
+
*
|
|
379
|
+
* // Error handling with Result
|
|
380
|
+
* const result = pipe(
|
|
381
|
+
* Result.tryCatch(() => JSON.parse(input), e => "Invalid JSON"),
|
|
382
|
+
* Result.map(data => data.value),
|
|
383
|
+
* Result.getOrElse(null)
|
|
384
|
+
* );
|
|
385
|
+
* ```
|
|
386
|
+
*
|
|
387
|
+
* @see {@link flow} for creating reusable pipelines without an initial value
|
|
388
|
+
*/
|
|
389
|
+
declare function pipe<A>(a: A): A;
|
|
390
|
+
declare function pipe<A, B>(a: A, ab: (a: A) => B): B;
|
|
391
|
+
declare function pipe<A, B, C>(a: A, ab: (a: A) => B, bc: (b: B) => C): C;
|
|
392
|
+
declare function pipe<A, B, C, D>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D): D;
|
|
393
|
+
declare function pipe<A, B, C, D, E>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E): E;
|
|
394
|
+
declare function pipe<A, B, C, D, E, F>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F): F;
|
|
395
|
+
declare function pipe<A, B, C, D, E, F, G>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G): G;
|
|
396
|
+
declare function pipe<A, B, C, D, E, F, G, H>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H): H;
|
|
397
|
+
declare function pipe<A, B, C, D, E, F, G, H, I>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I): I;
|
|
398
|
+
declare function pipe<A, B, C, D, E, F, G, H, I, J>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J): J;
|
|
399
|
+
declare function pipe<A, B, C, D, E, F, G, H, I, J, K>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K): K;
|
|
400
|
+
declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L): L;
|
|
401
|
+
declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M): M;
|
|
402
|
+
declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N): N;
|
|
403
|
+
declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O): O;
|
|
404
|
+
declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P): P;
|
|
405
|
+
declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Q): Q;
|
|
406
|
+
declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Q, qr: (q: Q) => R): R;
|
|
407
|
+
declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Q, qr: (q: Q) => R, rs: (r: R) => S): S;
|
|
408
|
+
declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Q, qr: (q: Q) => R, rs: (r: R) => S, st: (s: S) => T): T;
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Executes a side effect function and returns the original value unchanged.
|
|
412
|
+
* Useful for logging, debugging, or other side effects within a pipeline.
|
|
413
|
+
*
|
|
414
|
+
* @example
|
|
415
|
+
* ```ts
|
|
416
|
+
* // Debugging a pipeline
|
|
417
|
+
* pipe(
|
|
418
|
+
* Option.some(5),
|
|
419
|
+
* tap(x => console.log("Before map:", x)),
|
|
420
|
+
* Option.map(n => n * 2),
|
|
421
|
+
* tap(x => console.log("After map:", x)),
|
|
422
|
+
* Option.getOrElse(0)
|
|
423
|
+
* );
|
|
424
|
+
* // logs: "Before map: { kind: 'Some', value: 5 }"
|
|
425
|
+
* // logs: "After map: { kind: 'Some', value: 10 }"
|
|
426
|
+
* // returns: 10
|
|
427
|
+
*
|
|
428
|
+
* // Collecting intermediate values
|
|
429
|
+
* const values: number[] = [];
|
|
430
|
+
* pipe(
|
|
431
|
+
* [1, 2, 3],
|
|
432
|
+
* arr => arr.map(n => n * 2),
|
|
433
|
+
* tap(arr => values.push(...arr))
|
|
434
|
+
* );
|
|
435
|
+
* ```
|
|
436
|
+
*
|
|
437
|
+
* @see {@link Option.tap} for Option-specific tap that only runs on Some
|
|
438
|
+
*/
|
|
439
|
+
declare const tap: <A>(f: (a: A) => void) => (a: A) => A;
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Converts a curried function into a multi-argument function.
|
|
443
|
+
* Useful when you want to call a curried function with all arguments at once.
|
|
444
|
+
*
|
|
445
|
+
* Handles functions with 0, 1, or 2 curried arguments.
|
|
446
|
+
*
|
|
447
|
+
* @example
|
|
448
|
+
* ```ts
|
|
449
|
+
* // Thunks: () => () => C becomes () => C
|
|
450
|
+
* const nested = () => () => 42;
|
|
451
|
+
* uncurry(nested)(); // 42
|
|
452
|
+
*
|
|
453
|
+
* // Original curried function
|
|
454
|
+
* Option.map(n => n * 2)(Option.some(5)); // Some(10)
|
|
455
|
+
*
|
|
456
|
+
* // Uncurried - all arguments at once
|
|
457
|
+
* const mapUncurried = uncurry(Option.map);
|
|
458
|
+
* mapUncurried(n => n * 2, Option.some(5)); // Some(10)
|
|
459
|
+
*
|
|
460
|
+
* // Combined with flip for data-first uncurried
|
|
461
|
+
* const mapDataFirst = uncurry(flip(Option.map));
|
|
462
|
+
* mapDataFirst(Option.some(5), n => n * 2); // Some(10)
|
|
463
|
+
* ```
|
|
464
|
+
*
|
|
465
|
+
* @see {@link flip} for reversing curried argument order
|
|
466
|
+
* @see {@link uncurry3} for 3-argument curried functions
|
|
467
|
+
* @see {@link uncurry4} for 4-argument curried functions
|
|
468
|
+
*/
|
|
469
|
+
declare function uncurry<C>(f: () => () => C): () => C;
|
|
470
|
+
declare function uncurry<A, C>(f: (a: A) => () => C): (a: A) => C;
|
|
471
|
+
declare function uncurry<A, B, C>(f: (a: A) => (b: B) => C): (a: A, b: B) => C;
|
|
472
|
+
/**
|
|
473
|
+
* Converts a curried 3-argument function into a multi-argument function.
|
|
474
|
+
*
|
|
475
|
+
* @example
|
|
476
|
+
* ```ts
|
|
477
|
+
* const curriedAdd3 = (a: number) => (b: number) => (c: number) => a + b + c;
|
|
478
|
+
* const add3 = uncurry3(curriedAdd3);
|
|
479
|
+
* add3(1, 2, 3); // 6
|
|
480
|
+
* ```
|
|
481
|
+
*/
|
|
482
|
+
declare const uncurry3: <A, B, C, D>(f: (a: A) => (b: B) => (c: C) => D) => (a: A, b: B, c: C) => D;
|
|
483
|
+
/**
|
|
484
|
+
* Converts a curried 4-argument function into a multi-argument function.
|
|
485
|
+
*
|
|
486
|
+
* @example
|
|
487
|
+
* ```ts
|
|
488
|
+
* const curriedAdd4 = (a: number) => (b: number) => (c: number) => (d: number) => a + b + c + d;
|
|
489
|
+
* const add4 = uncurry4(curriedAdd4);
|
|
490
|
+
* add4(1, 2, 3, 4); // 10
|
|
491
|
+
* ```
|
|
492
|
+
*/
|
|
493
|
+
declare const uncurry4: <A, B, C, D, E>(f: (a: A) => (b: B) => (c: C) => (d: D) => E) => (a: A, b: B, c: C, d: D) => E;
|
|
494
|
+
|
|
495
|
+
export { and, compose, constFalse, constNull, constTrue, constUndefined, constVoid, constant, converge, curry, curry3, curry4, flip, flow, identity, juxt, memoize, memoizeWeak, not, on, once, or, pipe, tap, uncurry, uncurry3, uncurry4 };
|
|
@@ -0,0 +1,188 @@
|
|
|
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
|
+
flip: () => flip,
|
|
36
|
+
flow: () => flow,
|
|
37
|
+
identity: () => identity,
|
|
38
|
+
juxt: () => juxt,
|
|
39
|
+
memoize: () => memoize,
|
|
40
|
+
memoizeWeak: () => memoizeWeak,
|
|
41
|
+
not: () => not,
|
|
42
|
+
on: () => on,
|
|
43
|
+
once: () => once,
|
|
44
|
+
or: () => or,
|
|
45
|
+
pipe: () => pipe,
|
|
46
|
+
tap: () => tap,
|
|
47
|
+
uncurry: () => uncurry,
|
|
48
|
+
uncurry3: () => uncurry3,
|
|
49
|
+
uncurry4: () => uncurry4
|
|
50
|
+
});
|
|
51
|
+
module.exports = __toCommonJS(Composition_exports);
|
|
52
|
+
|
|
53
|
+
// src/Composition/compose.ts
|
|
54
|
+
function compose(...fns) {
|
|
55
|
+
return (arg) => fns.reduceRight((acc, fn) => fn(acc), arg);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// src/Composition/converge.ts
|
|
59
|
+
function converge(f, transformers) {
|
|
60
|
+
return (a) => f(...transformers.map((t) => t(a)));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/Composition/curry.ts
|
|
64
|
+
var curry = (f) => (a) => (b) => f(a, b);
|
|
65
|
+
var curry3 = (f) => (a) => (b) => (c) => f(a, b, c);
|
|
66
|
+
var curry4 = (f) => (a) => (b) => (c) => (d) => f(a, b, c, d);
|
|
67
|
+
|
|
68
|
+
// src/Composition/flip.ts
|
|
69
|
+
var flip = (f) => (b) => (a) => f(a)(b);
|
|
70
|
+
|
|
71
|
+
// src/Composition/flow.ts
|
|
72
|
+
function flow(...fns) {
|
|
73
|
+
return (...args) => {
|
|
74
|
+
if (fns.length === 0) return args[0];
|
|
75
|
+
const [first, ...rest] = fns;
|
|
76
|
+
return rest.reduce((acc, fn) => fn(acc), first(...args));
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/Composition/fn.ts
|
|
81
|
+
var identity = (a) => a;
|
|
82
|
+
var constant = (a) => () => a;
|
|
83
|
+
var constTrue = () => true;
|
|
84
|
+
var constFalse = () => false;
|
|
85
|
+
var constNull = () => null;
|
|
86
|
+
var constUndefined = () => void 0;
|
|
87
|
+
var constVoid = () => {
|
|
88
|
+
};
|
|
89
|
+
var and = (p1, p2) => (...args) => p1(...args) && p2(...args);
|
|
90
|
+
var or = (p1, p2) => (...args) => p1(...args) || p2(...args);
|
|
91
|
+
var once = (f) => {
|
|
92
|
+
let called = false;
|
|
93
|
+
let result;
|
|
94
|
+
return () => {
|
|
95
|
+
if (!called) {
|
|
96
|
+
result = f();
|
|
97
|
+
called = true;
|
|
98
|
+
}
|
|
99
|
+
return result;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// src/Composition/juxt.ts
|
|
104
|
+
function juxt(fns) {
|
|
105
|
+
return (a) => fns.map((f) => f(a));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// src/Composition/memoize.ts
|
|
109
|
+
var memoize = (f, keyFn = (a) => a) => {
|
|
110
|
+
const cache = /* @__PURE__ */ new Map();
|
|
111
|
+
return (a) => {
|
|
112
|
+
const key = keyFn(a);
|
|
113
|
+
if (cache.has(key)) {
|
|
114
|
+
return cache.get(key);
|
|
115
|
+
}
|
|
116
|
+
const result = f(a);
|
|
117
|
+
cache.set(key, result);
|
|
118
|
+
return result;
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
var memoizeWeak = (f) => {
|
|
122
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
123
|
+
return (a) => {
|
|
124
|
+
if (cache.has(a)) {
|
|
125
|
+
return cache.get(a);
|
|
126
|
+
}
|
|
127
|
+
const result = f(a);
|
|
128
|
+
cache.set(a, result);
|
|
129
|
+
return result;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// src/Composition/not.ts
|
|
134
|
+
var not = (predicate) => (...args) => !predicate(...args);
|
|
135
|
+
|
|
136
|
+
// src/Composition/on.ts
|
|
137
|
+
var on = (f, g) => (a, b) => f(g(a), g(b));
|
|
138
|
+
|
|
139
|
+
// src/Composition/pipe.ts
|
|
140
|
+
function pipe(a, ...fns) {
|
|
141
|
+
return fns.reduce((acc, fn) => fn(acc), a);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/Composition/tap.ts
|
|
145
|
+
var tap = (f) => (a) => {
|
|
146
|
+
f(a);
|
|
147
|
+
return a;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// src/Composition/uncurry.ts
|
|
151
|
+
function uncurry(f) {
|
|
152
|
+
return (...args) => {
|
|
153
|
+
const inner = f(...args.slice(0, f.length));
|
|
154
|
+
return inner.length === 0 ? inner() : inner(...args.slice(f.length));
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
var uncurry3 = (f) => (a, b, c) => f(a)(b)(c);
|
|
158
|
+
var uncurry4 = (f) => (a, b, c, d) => f(a)(b)(c)(d);
|
|
159
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
160
|
+
0 && (module.exports = {
|
|
161
|
+
and,
|
|
162
|
+
compose,
|
|
163
|
+
constFalse,
|
|
164
|
+
constNull,
|
|
165
|
+
constTrue,
|
|
166
|
+
constUndefined,
|
|
167
|
+
constVoid,
|
|
168
|
+
constant,
|
|
169
|
+
converge,
|
|
170
|
+
curry,
|
|
171
|
+
curry3,
|
|
172
|
+
curry4,
|
|
173
|
+
flip,
|
|
174
|
+
flow,
|
|
175
|
+
identity,
|
|
176
|
+
juxt,
|
|
177
|
+
memoize,
|
|
178
|
+
memoizeWeak,
|
|
179
|
+
not,
|
|
180
|
+
on,
|
|
181
|
+
once,
|
|
182
|
+
or,
|
|
183
|
+
pipe,
|
|
184
|
+
tap,
|
|
185
|
+
uncurry,
|
|
186
|
+
uncurry3,
|
|
187
|
+
uncurry4
|
|
188
|
+
});
|