@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.
Files changed (213) 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-Bd3gXPRQ.d.mts +677 -0
  6. package/dist/Task-BjAkkD6t.d.ts +677 -0
  7. package/dist/chunk-4TXC322E.mjs +136 -0
  8. package/dist/chunk-BYWKZLHM.mjs +10 -0
  9. package/dist/chunk-DBIC62UV.mjs +6 -0
  10. package/dist/chunk-FAZN3IWZ.mjs +554 -0
  11. package/dist/chunk-QPTGO5AS.mjs +150 -0
  12. package/dist/chunk-UV2HMF2A.mjs +514 -0
  13. package/dist/composition.d.mts +495 -0
  14. package/dist/composition.d.ts +495 -0
  15. package/dist/composition.js +188 -0
  16. package/dist/composition.mjs +58 -0
  17. package/dist/core.d.mts +2170 -0
  18. package/dist/core.d.ts +2170 -0
  19. package/dist/core.js +698 -0
  20. package/dist/core.mjs +42 -0
  21. package/dist/index.d.mts +6 -0
  22. package/dist/index.d.ts +6 -0
  23. package/dist/index.js +1421 -0
  24. package/dist/index.mjs +120 -0
  25. package/dist/types.d.mts +54 -0
  26. package/{types/src/Types/Brand.d.ts → dist/types.d.ts} +6 -4
  27. package/dist/types.js +41 -0
  28. package/dist/types.mjs +10 -0
  29. package/dist/utils.d.mts +1285 -0
  30. package/dist/utils.d.ts +1285 -0
  31. package/dist/utils.js +722 -0
  32. package/dist/utils.mjs +18 -0
  33. package/package.json +64 -69
  34. package/esm/mod.js +0 -3
  35. package/esm/package.json +0 -3
  36. package/esm/src/Composition/compose.js +0 -3
  37. package/esm/src/Composition/converge.js +0 -3
  38. package/esm/src/Composition/curry.js +0 -42
  39. package/esm/src/Composition/flip.js +0 -20
  40. package/esm/src/Composition/flow.js +0 -8
  41. package/esm/src/Composition/fn.js +0 -85
  42. package/esm/src/Composition/index.js +0 -13
  43. package/esm/src/Composition/juxt.js +0 -3
  44. package/esm/src/Composition/memoize.js +0 -66
  45. package/esm/src/Composition/not.js +0 -25
  46. package/esm/src/Composition/on.js +0 -12
  47. package/esm/src/Composition/pipe.js +0 -3
  48. package/esm/src/Composition/tap.js +0 -33
  49. package/esm/src/Composition/uncurry.js +0 -32
  50. package/esm/src/Core/Deferred.js +0 -30
  51. package/esm/src/Core/InternalTypes.js +0 -1
  52. package/esm/src/Core/Lens.js +0 -98
  53. package/esm/src/Core/Logged.js +0 -111
  54. package/esm/src/Core/Option.js +0 -191
  55. package/esm/src/Core/Optional.js +0 -160
  56. package/esm/src/Core/Predicate.js +0 -133
  57. package/esm/src/Core/Reader.js +0 -134
  58. package/esm/src/Core/Refinement.js +0 -115
  59. package/esm/src/Core/RemoteData.js +0 -211
  60. package/esm/src/Core/Result.js +0 -170
  61. package/esm/src/Core/State.js +0 -181
  62. package/esm/src/Core/Task.js +0 -223
  63. package/esm/src/Core/TaskOption.js +0 -106
  64. package/esm/src/Core/TaskResult.js +0 -127
  65. package/esm/src/Core/TaskValidation.js +0 -128
  66. package/esm/src/Core/These.js +0 -245
  67. package/esm/src/Core/Tuple.js +0 -112
  68. package/esm/src/Core/Validation.js +0 -212
  69. package/esm/src/Core/index.js +0 -18
  70. package/esm/src/Types/Brand.js +0 -28
  71. package/esm/src/Types/NonEmptyList.js +0 -14
  72. package/esm/src/Types/index.js +0 -2
  73. package/esm/src/Utils/Arr.js +0 -570
  74. package/esm/src/Utils/Dict.js +0 -421
  75. package/esm/src/Utils/Num.js +0 -124
  76. package/esm/src/Utils/Rec.js +0 -241
  77. package/esm/src/Utils/Str.js +0 -134
  78. package/esm/src/Utils/Uniq.js +0 -265
  79. package/esm/src/Utils/index.js +0 -6
  80. package/script/mod.js +0 -19
  81. package/script/package.json +0 -3
  82. package/script/src/Composition/compose.js +0 -6
  83. package/script/src/Composition/converge.js +0 -6
  84. package/script/src/Composition/curry.js +0 -48
  85. package/script/src/Composition/flip.js +0 -24
  86. package/script/src/Composition/flow.js +0 -11
  87. package/script/src/Composition/fn.js +0 -98
  88. package/script/src/Composition/index.js +0 -29
  89. package/script/src/Composition/juxt.js +0 -6
  90. package/script/src/Composition/memoize.js +0 -71
  91. package/script/src/Composition/not.js +0 -29
  92. package/script/src/Composition/on.js +0 -16
  93. package/script/src/Composition/pipe.js +0 -6
  94. package/script/src/Composition/tap.js +0 -37
  95. package/script/src/Composition/uncurry.js +0 -38
  96. package/script/src/Core/Deferred.js +0 -33
  97. package/script/src/Core/InternalTypes.js +0 -2
  98. package/script/src/Core/Lens.js +0 -101
  99. package/script/src/Core/Logged.js +0 -114
  100. package/script/src/Core/Option.js +0 -194
  101. package/script/src/Core/Optional.js +0 -163
  102. package/script/src/Core/Predicate.js +0 -136
  103. package/script/src/Core/Reader.js +0 -137
  104. package/script/src/Core/Refinement.js +0 -118
  105. package/script/src/Core/RemoteData.js +0 -214
  106. package/script/src/Core/Result.js +0 -173
  107. package/script/src/Core/State.js +0 -184
  108. package/script/src/Core/Task.js +0 -226
  109. package/script/src/Core/TaskOption.js +0 -109
  110. package/script/src/Core/TaskResult.js +0 -130
  111. package/script/src/Core/TaskValidation.js +0 -131
  112. package/script/src/Core/These.js +0 -248
  113. package/script/src/Core/Tuple.js +0 -115
  114. package/script/src/Core/Validation.js +0 -215
  115. package/script/src/Core/index.js +0 -34
  116. package/script/src/Types/Brand.js +0 -31
  117. package/script/src/Types/NonEmptyList.js +0 -18
  118. package/script/src/Types/index.js +0 -18
  119. package/script/src/Utils/Arr.js +0 -573
  120. package/script/src/Utils/Dict.js +0 -424
  121. package/script/src/Utils/Num.js +0 -127
  122. package/script/src/Utils/Rec.js +0 -244
  123. package/script/src/Utils/Str.js +0 -137
  124. package/script/src/Utils/Uniq.js +0 -268
  125. package/script/src/Utils/index.js +0 -22
  126. package/types/mod.d.ts +0 -4
  127. package/types/mod.d.ts.map +0 -1
  128. package/types/src/Composition/compose.d.ts +0 -33
  129. package/types/src/Composition/compose.d.ts.map +0 -1
  130. package/types/src/Composition/converge.d.ts +0 -21
  131. package/types/src/Composition/converge.d.ts.map +0 -1
  132. package/types/src/Composition/curry.d.ts +0 -43
  133. package/types/src/Composition/curry.d.ts.map +0 -1
  134. package/types/src/Composition/flip.d.ts +0 -21
  135. package/types/src/Composition/flip.d.ts.map +0 -1
  136. package/types/src/Composition/flow.d.ts +0 -56
  137. package/types/src/Composition/flow.d.ts.map +0 -1
  138. package/types/src/Composition/fn.d.ts +0 -76
  139. package/types/src/Composition/fn.d.ts.map +0 -1
  140. package/types/src/Composition/index.d.ts +0 -14
  141. package/types/src/Composition/index.d.ts.map +0 -1
  142. package/types/src/Composition/juxt.d.ts +0 -18
  143. package/types/src/Composition/juxt.d.ts.map +0 -1
  144. package/types/src/Composition/memoize.d.ts +0 -46
  145. package/types/src/Composition/memoize.d.ts.map +0 -1
  146. package/types/src/Composition/not.d.ts +0 -26
  147. package/types/src/Composition/not.d.ts.map +0 -1
  148. package/types/src/Composition/on.d.ts +0 -13
  149. package/types/src/Composition/on.d.ts.map +0 -1
  150. package/types/src/Composition/pipe.d.ts +0 -56
  151. package/types/src/Composition/pipe.d.ts.map +0 -1
  152. package/types/src/Composition/tap.d.ts +0 -31
  153. package/types/src/Composition/tap.d.ts.map +0 -1
  154. package/types/src/Composition/uncurry.d.ts +0 -54
  155. package/types/src/Composition/uncurry.d.ts.map +0 -1
  156. package/types/src/Core/Deferred.d.ts +0 -49
  157. package/types/src/Core/Deferred.d.ts.map +0 -1
  158. package/types/src/Core/InternalTypes.d.ts +0 -23
  159. package/types/src/Core/InternalTypes.d.ts.map +0 -1
  160. package/types/src/Core/Lens.d.ts +0 -118
  161. package/types/src/Core/Lens.d.ts.map +0 -1
  162. package/types/src/Core/Logged.d.ts +0 -126
  163. package/types/src/Core/Logged.d.ts.map +0 -1
  164. package/types/src/Core/Option.d.ts +0 -209
  165. package/types/src/Core/Option.d.ts.map +0 -1
  166. package/types/src/Core/Optional.d.ts +0 -158
  167. package/types/src/Core/Optional.d.ts.map +0 -1
  168. package/types/src/Core/Predicate.d.ts +0 -161
  169. package/types/src/Core/Predicate.d.ts.map +0 -1
  170. package/types/src/Core/Reader.d.ts +0 -156
  171. package/types/src/Core/Reader.d.ts.map +0 -1
  172. package/types/src/Core/Refinement.d.ts +0 -138
  173. package/types/src/Core/Refinement.d.ts.map +0 -1
  174. package/types/src/Core/RemoteData.d.ts +0 -197
  175. package/types/src/Core/RemoteData.d.ts.map +0 -1
  176. package/types/src/Core/Result.d.ts +0 -182
  177. package/types/src/Core/Result.d.ts.map +0 -1
  178. package/types/src/Core/State.d.ts +0 -192
  179. package/types/src/Core/State.d.ts.map +0 -1
  180. package/types/src/Core/Task.d.ts +0 -219
  181. package/types/src/Core/Task.d.ts.map +0 -1
  182. package/types/src/Core/TaskOption.d.ts +0 -121
  183. package/types/src/Core/TaskOption.d.ts.map +0 -1
  184. package/types/src/Core/TaskResult.d.ts +0 -119
  185. package/types/src/Core/TaskResult.d.ts.map +0 -1
  186. package/types/src/Core/TaskValidation.d.ts +0 -144
  187. package/types/src/Core/TaskValidation.d.ts.map +0 -1
  188. package/types/src/Core/These.d.ts +0 -225
  189. package/types/src/Core/These.d.ts.map +0 -1
  190. package/types/src/Core/Tuple.d.ts +0 -129
  191. package/types/src/Core/Tuple.d.ts.map +0 -1
  192. package/types/src/Core/Validation.d.ts +0 -203
  193. package/types/src/Core/Validation.d.ts.map +0 -1
  194. package/types/src/Core/index.d.ts +0 -19
  195. package/types/src/Core/index.d.ts.map +0 -1
  196. package/types/src/Types/Brand.d.ts.map +0 -1
  197. package/types/src/Types/NonEmptyList.d.ts.map +0 -1
  198. package/types/src/Types/index.d.ts +0 -3
  199. package/types/src/Types/index.d.ts.map +0 -1
  200. package/types/src/Utils/Arr.d.ts +0 -403
  201. package/types/src/Utils/Arr.d.ts.map +0 -1
  202. package/types/src/Utils/Dict.d.ts +0 -310
  203. package/types/src/Utils/Dict.d.ts.map +0 -1
  204. package/types/src/Utils/Num.d.ts +0 -110
  205. package/types/src/Utils/Num.d.ts.map +0 -1
  206. package/types/src/Utils/Rec.d.ts +0 -159
  207. package/types/src/Utils/Rec.d.ts.map +0 -1
  208. package/types/src/Utils/Str.d.ts +0 -128
  209. package/types/src/Utils/Str.d.ts.map +0 -1
  210. package/types/src/Utils/Uniq.d.ts +0 -179
  211. package/types/src/Utils/Uniq.d.ts.map +0 -1
  212. package/types/src/Utils/index.d.ts +0 -7
  213. package/types/src/Utils/index.d.ts.map +0 -1
package/dist/utils.mjs ADDED
@@ -0,0 +1,18 @@
1
+ import {
2
+ Arr,
3
+ Dict,
4
+ Num,
5
+ Rec,
6
+ Str,
7
+ Uniq
8
+ } from "./chunk-FAZN3IWZ.mjs";
9
+ import "./chunk-QPTGO5AS.mjs";
10
+ import "./chunk-DBIC62UV.mjs";
11
+ export {
12
+ Arr,
13
+ Dict,
14
+ Num,
15
+ Rec,
16
+ Str,
17
+ Uniq
18
+ };
package/package.json CHANGED
@@ -1,71 +1,66 @@
1
1
  {
2
- "name": "@nlozgachev/pipelined",
3
- "version": "0.12.0",
4
- "description": "Simple functional programming toolkit for TypeScript",
5
- "keywords": [
6
- "functional",
7
- "fp",
8
- "typescript",
9
- "composition",
10
- "pipe"
11
- ],
12
- "homepage": "https://pipelined.lozgachev.dev",
13
- "repository": {
14
- "type": "git",
15
- "url": "https://github.com/nlozgachev/pipelined"
16
- },
17
- "license": "BSD-3-Clause",
18
- "types": "./types/mod.d.ts",
19
- "exports": {
20
- "./composition": {
21
- "import": {
22
- "types": "./types/src/Composition/index.d.ts",
23
- "default": "./esm/src/Composition/index.js"
24
- },
25
- "require": {
26
- "types": "./types/src/Composition/index.d.ts",
27
- "default": "./script/src/Composition/index.js"
28
- }
29
- },
30
- "./core": {
31
- "import": {
32
- "types": "./types/src/Core/index.d.ts",
33
- "default": "./esm/src/Core/index.js"
34
- },
35
- "require": {
36
- "types": "./types/src/Core/index.d.ts",
37
- "default": "./script/src/Core/index.js"
38
- }
39
- },
40
- "./utils": {
41
- "import": {
42
- "types": "./types/src/Utils/index.d.ts",
43
- "default": "./esm/src/Utils/index.js"
44
- },
45
- "require": {
46
- "types": "./types/src/Utils/index.d.ts",
47
- "default": "./script/src/Utils/index.js"
48
- }
49
- },
50
- "./types": {
51
- "import": {
52
- "types": "./types/src/Types/index.d.ts",
53
- "default": "./esm/src/Types/index.js"
54
- },
55
- "require": {
56
- "types": "./types/src/Types/index.d.ts",
57
- "default": "./script/src/Types/index.js"
58
- }
59
- }
60
- },
61
- "scripts": {},
62
- "sideEffects": false,
63
- "engines": {
64
- "node": ">=22"
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
@@ -1,3 +0,0 @@
1
- export * from "./src/Composition/index.js";
2
- export * from "./src/Core/index.js";
3
- export * from "./src/Composition/index.js";
package/esm/package.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }
@@ -1,3 +0,0 @@
1
- export function compose(...fns) {
2
- return (arg) => fns.reduceRight((acc, fn) => fn(acc), arg);
3
- }
@@ -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 = {}));