@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.
Files changed (205) hide show
  1. package/LICENCE +28 -0
  2. package/README.md +1 -1
  3. package/{types/src/Types/NonEmptyList.d.ts → dist/NonEmptyList-BlGFjor5.d.mts} +4 -3
  4. package/dist/NonEmptyList-BlGFjor5.d.ts +30 -0
  5. package/dist/Task-BB8Wmc1J.d.ts +677 -0
  6. package/dist/Task-ChKyH0pF.d.mts +677 -0
  7. package/dist/chunk-DBIC62UV.mjs +6 -0
  8. package/dist/chunk-QPTGO5AS.mjs +150 -0
  9. package/dist/composition.d.mts +495 -0
  10. package/dist/composition.d.ts +495 -0
  11. package/dist/composition.js +188 -0
  12. package/dist/composition.mjs +135 -0
  13. package/dist/core.d.mts +2170 -0
  14. package/dist/core.d.ts +2170 -0
  15. package/dist/core.js +698 -0
  16. package/dist/core.mjs +517 -0
  17. package/dist/types.d.mts +54 -0
  18. package/{types/src/Types/Brand.d.ts → dist/types.d.ts} +6 -4
  19. package/dist/types.js +41 -0
  20. package/dist/types.mjs +14 -0
  21. package/dist/utils.d.mts +1285 -0
  22. package/dist/utils.d.ts +1285 -0
  23. package/dist/utils.js +722 -0
  24. package/dist/utils.mjs +553 -0
  25. package/package.json +63 -69
  26. package/esm/mod.js +0 -3
  27. package/esm/package.json +0 -3
  28. package/esm/src/Composition/compose.js +0 -3
  29. package/esm/src/Composition/converge.js +0 -3
  30. package/esm/src/Composition/curry.js +0 -42
  31. package/esm/src/Composition/flip.js +0 -20
  32. package/esm/src/Composition/flow.js +0 -8
  33. package/esm/src/Composition/fn.js +0 -85
  34. package/esm/src/Composition/index.js +0 -13
  35. package/esm/src/Composition/juxt.js +0 -3
  36. package/esm/src/Composition/memoize.js +0 -66
  37. package/esm/src/Composition/not.js +0 -25
  38. package/esm/src/Composition/on.js +0 -12
  39. package/esm/src/Composition/pipe.js +0 -3
  40. package/esm/src/Composition/tap.js +0 -33
  41. package/esm/src/Composition/uncurry.js +0 -32
  42. package/esm/src/Core/Deferred.js +0 -30
  43. package/esm/src/Core/InternalTypes.js +0 -1
  44. package/esm/src/Core/Lens.js +0 -98
  45. package/esm/src/Core/Logged.js +0 -111
  46. package/esm/src/Core/Option.js +0 -191
  47. package/esm/src/Core/Optional.js +0 -160
  48. package/esm/src/Core/Predicate.js +0 -133
  49. package/esm/src/Core/Reader.js +0 -134
  50. package/esm/src/Core/Refinement.js +0 -115
  51. package/esm/src/Core/RemoteData.js +0 -211
  52. package/esm/src/Core/Result.js +0 -170
  53. package/esm/src/Core/State.js +0 -181
  54. package/esm/src/Core/Task.js +0 -223
  55. package/esm/src/Core/TaskOption.js +0 -106
  56. package/esm/src/Core/TaskResult.js +0 -127
  57. package/esm/src/Core/TaskValidation.js +0 -128
  58. package/esm/src/Core/These.js +0 -245
  59. package/esm/src/Core/Tuple.js +0 -112
  60. package/esm/src/Core/Validation.js +0 -212
  61. package/esm/src/Core/index.js +0 -18
  62. package/esm/src/Types/Brand.js +0 -28
  63. package/esm/src/Types/NonEmptyList.js +0 -14
  64. package/esm/src/Types/index.js +0 -2
  65. package/esm/src/Utils/Arr.js +0 -570
  66. package/esm/src/Utils/Dict.js +0 -421
  67. package/esm/src/Utils/Num.js +0 -124
  68. package/esm/src/Utils/Rec.js +0 -241
  69. package/esm/src/Utils/Str.js +0 -134
  70. package/esm/src/Utils/Uniq.js +0 -265
  71. package/esm/src/Utils/index.js +0 -6
  72. package/script/mod.js +0 -19
  73. package/script/package.json +0 -3
  74. package/script/src/Composition/compose.js +0 -6
  75. package/script/src/Composition/converge.js +0 -6
  76. package/script/src/Composition/curry.js +0 -48
  77. package/script/src/Composition/flip.js +0 -24
  78. package/script/src/Composition/flow.js +0 -11
  79. package/script/src/Composition/fn.js +0 -98
  80. package/script/src/Composition/index.js +0 -29
  81. package/script/src/Composition/juxt.js +0 -6
  82. package/script/src/Composition/memoize.js +0 -71
  83. package/script/src/Composition/not.js +0 -29
  84. package/script/src/Composition/on.js +0 -16
  85. package/script/src/Composition/pipe.js +0 -6
  86. package/script/src/Composition/tap.js +0 -37
  87. package/script/src/Composition/uncurry.js +0 -38
  88. package/script/src/Core/Deferred.js +0 -33
  89. package/script/src/Core/InternalTypes.js +0 -2
  90. package/script/src/Core/Lens.js +0 -101
  91. package/script/src/Core/Logged.js +0 -114
  92. package/script/src/Core/Option.js +0 -194
  93. package/script/src/Core/Optional.js +0 -163
  94. package/script/src/Core/Predicate.js +0 -136
  95. package/script/src/Core/Reader.js +0 -137
  96. package/script/src/Core/Refinement.js +0 -118
  97. package/script/src/Core/RemoteData.js +0 -214
  98. package/script/src/Core/Result.js +0 -173
  99. package/script/src/Core/State.js +0 -184
  100. package/script/src/Core/Task.js +0 -226
  101. package/script/src/Core/TaskOption.js +0 -109
  102. package/script/src/Core/TaskResult.js +0 -130
  103. package/script/src/Core/TaskValidation.js +0 -131
  104. package/script/src/Core/These.js +0 -248
  105. package/script/src/Core/Tuple.js +0 -115
  106. package/script/src/Core/Validation.js +0 -215
  107. package/script/src/Core/index.js +0 -34
  108. package/script/src/Types/Brand.js +0 -31
  109. package/script/src/Types/NonEmptyList.js +0 -18
  110. package/script/src/Types/index.js +0 -18
  111. package/script/src/Utils/Arr.js +0 -573
  112. package/script/src/Utils/Dict.js +0 -424
  113. package/script/src/Utils/Num.js +0 -127
  114. package/script/src/Utils/Rec.js +0 -244
  115. package/script/src/Utils/Str.js +0 -137
  116. package/script/src/Utils/Uniq.js +0 -268
  117. package/script/src/Utils/index.js +0 -22
  118. package/types/mod.d.ts +0 -4
  119. package/types/mod.d.ts.map +0 -1
  120. package/types/src/Composition/compose.d.ts +0 -33
  121. package/types/src/Composition/compose.d.ts.map +0 -1
  122. package/types/src/Composition/converge.d.ts +0 -21
  123. package/types/src/Composition/converge.d.ts.map +0 -1
  124. package/types/src/Composition/curry.d.ts +0 -43
  125. package/types/src/Composition/curry.d.ts.map +0 -1
  126. package/types/src/Composition/flip.d.ts +0 -21
  127. package/types/src/Composition/flip.d.ts.map +0 -1
  128. package/types/src/Composition/flow.d.ts +0 -56
  129. package/types/src/Composition/flow.d.ts.map +0 -1
  130. package/types/src/Composition/fn.d.ts +0 -76
  131. package/types/src/Composition/fn.d.ts.map +0 -1
  132. package/types/src/Composition/index.d.ts +0 -14
  133. package/types/src/Composition/index.d.ts.map +0 -1
  134. package/types/src/Composition/juxt.d.ts +0 -18
  135. package/types/src/Composition/juxt.d.ts.map +0 -1
  136. package/types/src/Composition/memoize.d.ts +0 -46
  137. package/types/src/Composition/memoize.d.ts.map +0 -1
  138. package/types/src/Composition/not.d.ts +0 -26
  139. package/types/src/Composition/not.d.ts.map +0 -1
  140. package/types/src/Composition/on.d.ts +0 -13
  141. package/types/src/Composition/on.d.ts.map +0 -1
  142. package/types/src/Composition/pipe.d.ts +0 -56
  143. package/types/src/Composition/pipe.d.ts.map +0 -1
  144. package/types/src/Composition/tap.d.ts +0 -31
  145. package/types/src/Composition/tap.d.ts.map +0 -1
  146. package/types/src/Composition/uncurry.d.ts +0 -54
  147. package/types/src/Composition/uncurry.d.ts.map +0 -1
  148. package/types/src/Core/Deferred.d.ts +0 -49
  149. package/types/src/Core/Deferred.d.ts.map +0 -1
  150. package/types/src/Core/InternalTypes.d.ts +0 -23
  151. package/types/src/Core/InternalTypes.d.ts.map +0 -1
  152. package/types/src/Core/Lens.d.ts +0 -118
  153. package/types/src/Core/Lens.d.ts.map +0 -1
  154. package/types/src/Core/Logged.d.ts +0 -126
  155. package/types/src/Core/Logged.d.ts.map +0 -1
  156. package/types/src/Core/Option.d.ts +0 -209
  157. package/types/src/Core/Option.d.ts.map +0 -1
  158. package/types/src/Core/Optional.d.ts +0 -158
  159. package/types/src/Core/Optional.d.ts.map +0 -1
  160. package/types/src/Core/Predicate.d.ts +0 -161
  161. package/types/src/Core/Predicate.d.ts.map +0 -1
  162. package/types/src/Core/Reader.d.ts +0 -156
  163. package/types/src/Core/Reader.d.ts.map +0 -1
  164. package/types/src/Core/Refinement.d.ts +0 -138
  165. package/types/src/Core/Refinement.d.ts.map +0 -1
  166. package/types/src/Core/RemoteData.d.ts +0 -197
  167. package/types/src/Core/RemoteData.d.ts.map +0 -1
  168. package/types/src/Core/Result.d.ts +0 -182
  169. package/types/src/Core/Result.d.ts.map +0 -1
  170. package/types/src/Core/State.d.ts +0 -192
  171. package/types/src/Core/State.d.ts.map +0 -1
  172. package/types/src/Core/Task.d.ts +0 -219
  173. package/types/src/Core/Task.d.ts.map +0 -1
  174. package/types/src/Core/TaskOption.d.ts +0 -121
  175. package/types/src/Core/TaskOption.d.ts.map +0 -1
  176. package/types/src/Core/TaskResult.d.ts +0 -119
  177. package/types/src/Core/TaskResult.d.ts.map +0 -1
  178. package/types/src/Core/TaskValidation.d.ts +0 -144
  179. package/types/src/Core/TaskValidation.d.ts.map +0 -1
  180. package/types/src/Core/These.d.ts +0 -225
  181. package/types/src/Core/These.d.ts.map +0 -1
  182. package/types/src/Core/Tuple.d.ts +0 -129
  183. package/types/src/Core/Tuple.d.ts.map +0 -1
  184. package/types/src/Core/Validation.d.ts +0 -203
  185. package/types/src/Core/Validation.d.ts.map +0 -1
  186. package/types/src/Core/index.d.ts +0 -19
  187. package/types/src/Core/index.d.ts.map +0 -1
  188. package/types/src/Types/Brand.d.ts.map +0 -1
  189. package/types/src/Types/NonEmptyList.d.ts.map +0 -1
  190. package/types/src/Types/index.d.ts +0 -3
  191. package/types/src/Types/index.d.ts.map +0 -1
  192. package/types/src/Utils/Arr.d.ts +0 -403
  193. package/types/src/Utils/Arr.d.ts.map +0 -1
  194. package/types/src/Utils/Dict.d.ts +0 -310
  195. package/types/src/Utils/Dict.d.ts.map +0 -1
  196. package/types/src/Utils/Num.d.ts +0 -110
  197. package/types/src/Utils/Num.d.ts.map +0 -1
  198. package/types/src/Utils/Rec.d.ts +0 -159
  199. package/types/src/Utils/Rec.d.ts.map +0 -1
  200. package/types/src/Utils/Str.d.ts +0 -128
  201. package/types/src/Utils/Str.d.ts.map +0 -1
  202. package/types/src/Utils/Uniq.d.ts +0 -179
  203. package/types/src/Utils/Uniq.d.ts.map +0 -1
  204. package/types/src/Utils/index.d.ts +0 -7
  205. package/types/src/Utils/index.d.ts.map +0 -1
@@ -1,3 +0,0 @@
1
- export function converge(f, transformers) {
2
- return (a) => f(...transformers.map((t) => t(a)));
3
- }
@@ -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,8 +0,0 @@
1
- export function flow(...fns) {
2
- return (...args) => {
3
- if (fns.length === 0)
4
- return args[0];
5
- const [first, ...rest] = fns;
6
- return rest.reduce((acc, fn) => fn(acc), first(...args));
7
- };
8
- }
@@ -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,3 +0,0 @@
1
- export function juxt(fns) {
2
- return (a) => fns.map((f) => f(a));
3
- }
@@ -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,3 +0,0 @@
1
- export function pipe(a, ...fns) {
2
- return fns.reduce((acc, fn) => fn(acc), a);
3
- }
@@ -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);
@@ -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 {};
@@ -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 = {}));
@@ -1,111 +0,0 @@
1
- export var Logged;
2
- (function (Logged) {
3
- /**
4
- * Wraps a pure value into a `Logged` with an empty log.
5
- *
6
- * @example
7
- * ```ts
8
- * Logged.make<string, number>(42); // { value: 42, log: [] }
9
- * ```
10
- */
11
- Logged.make = (value) => ({ value, log: [] });
12
- /**
13
- * Creates a `Logged` that records a single log entry and produces no
14
- * meaningful value. Use this to append to the log inside a `chain`.
15
- *
16
- * @example
17
- * ```ts
18
- * Logged.tell("operation completed"); // { value: undefined, log: ["operation completed"] }
19
- * ```
20
- */
21
- Logged.tell = (entry) => ({ value: undefined, log: [entry] });
22
- /**
23
- * Transforms the value inside a `Logged` without affecting the log.
24
- *
25
- * @example
26
- * ```ts
27
- * pipe(
28
- * Logged.make<string, number>(5),
29
- * Logged.map(n => n * 2),
30
- * ); // { value: 10, log: [] }
31
- * ```
32
- */
33
- Logged.map = (f) => (data) => ({
34
- value: f(data.value),
35
- log: data.log,
36
- });
37
- /**
38
- * Sequences two `Logged` computations, concatenating their logs.
39
- * The value from the first is passed to `f`; the resulting log entries are
40
- * appended after the entries from the first.
41
- *
42
- * Data-last — the first computation is the data being piped.
43
- *
44
- * @example
45
- * ```ts
46
- * const result = pipe(
47
- * Logged.make<string, number>(1),
48
- * Logged.chain(n => pipe(Logged.tell("step"), Logged.map(() => n + 1))),
49
- * Logged.chain(n => pipe(Logged.tell("done"), Logged.map(() => n * 10))),
50
- * );
51
- *
52
- * Logged.run(result); // [20, ["step", "done"]]
53
- * ```
54
- */
55
- Logged.chain = (f) => (data) => {
56
- const next = f(data.value);
57
- return { value: next.value, log: [...data.log, ...next.log] };
58
- };
59
- /**
60
- * Applies a function wrapped in a `Logged` to a value wrapped in a `Logged`,
61
- * concatenating both logs.
62
- *
63
- * @example
64
- * ```ts
65
- * const fn: Logged<string, (n: number) => number> = {
66
- * value: n => n * 2,
67
- * log: ["fn-loaded"],
68
- * };
69
- * const arg: Logged<string, number> = { value: 5, log: ["arg-loaded"] };
70
- *
71
- * const result = pipe(fn, Logged.ap(arg));
72
- * Logged.run(result); // [10, ["fn-loaded", "arg-loaded"]]
73
- * ```
74
- */
75
- Logged.ap = (arg) => (data) => ({
76
- value: data.value(arg.value),
77
- log: [...data.log, ...arg.log],
78
- });
79
- /**
80
- * Runs a side effect on the value without changing the `Logged`.
81
- * Useful for debugging or inspecting intermediate values.
82
- *
83
- * @example
84
- * ```ts
85
- * pipe(
86
- * Logged.make<string, number>(42),
87
- * Logged.tap(n => console.log("value:", n)),
88
- * );
89
- * ```
90
- */
91
- Logged.tap = (f) => (data) => {
92
- f(data.value);
93
- return data;
94
- };
95
- /**
96
- * Extracts the value and log as a `readonly [A, ReadonlyArray<W>]` tuple.
97
- * Use this at the boundary where you need to consume both.
98
- *
99
- * @example
100
- * ```ts
101
- * const result = pipe(
102
- * Logged.make<string, number>(1),
103
- * Logged.chain(n => pipe(Logged.tell("incremented"), Logged.map(() => n + 1))),
104
- * );
105
- *
106
- * const [value, log] = Logged.run(result);
107
- * // value = 2, log = ["incremented"]
108
- * ```
109
- */
110
- Logged.run = (data) => [data.value, data.log];
111
- })(Logged || (Logged = {}));