@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
@@ -1,194 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Option = void 0;
4
- const Result_js_1 = require("./Result.js");
5
- const _none = { kind: "None" };
6
- var Option;
7
- (function (Option) {
8
- /**
9
- * Creates a Some containing the given value.
10
- */
11
- Option.some = (value) => ({ kind: "Some", value });
12
- /**
13
- * Type guard that checks if a Option is Some.
14
- */
15
- Option.isSome = (data) => data.kind === "Some";
16
- /**
17
- * Creates a None (empty Option).
18
- */
19
- Option.none = () => _none;
20
- /**
21
- * Type guard that checks if a Option is None.
22
- */
23
- Option.isNone = (data) => data.kind === "None";
24
- /**
25
- * Creates a Option from a nullable value.
26
- * Returns None if the value is null or undefined, Some otherwise.
27
- *
28
- * @example
29
- * ```ts
30
- * Option.fromNullable(null); // None
31
- * Option.fromNullable(42); // Some(42)
32
- * ```
33
- */
34
- Option.fromNullable = (value) => value === null || value === undefined ? Option.none() : Option.some(value);
35
- /**
36
- * Extracts the value from a Option, returning null if None.
37
- */
38
- Option.toNullable = (data) => Option.isSome(data) ? data.value : null;
39
- /**
40
- * Extracts the value from a Option, returning undefined if None.
41
- */
42
- Option.toUndefined = (data) => Option.isSome(data) ? data.value : undefined;
43
- /**
44
- * Creates a Option from a possibly undefined value.
45
- * Returns None if undefined, Some otherwise.
46
- */
47
- Option.fromUndefined = (value) => value === undefined ? Option.none() : Option.some(value);
48
- /**
49
- * Converts an Option to a Result.
50
- * Some becomes Ok, None becomes Err with the provided error.
51
- *
52
- * @example
53
- * ```ts
54
- * pipe(
55
- * Option.some(42),
56
- * Option.toResult(() => "Value was missing")
57
- * ); // Ok(42)
58
- *
59
- * pipe(
60
- * Option.none(),
61
- * Option.toResult(() => "Value was missing")
62
- * ); // Err("Value was missing")
63
- * ```
64
- */
65
- Option.toResult = (onNone) => (data) => Option.isSome(data) ? Result_js_1.Result.ok(data.value) : Result_js_1.Result.err(onNone());
66
- /**
67
- * Creates an Option from a Result.
68
- * Ok becomes Some, Err becomes None (the error is discarded).
69
- *
70
- * @example
71
- * ```ts
72
- * Option.fromResult(Result.ok(42)); // Some(42)
73
- * Option.fromResult(Result.err("oops")); // None
74
- * ```
75
- */
76
- Option.fromResult = (data) => Result_js_1.Result.isOk(data) ? Option.some(data.value) : Option.none();
77
- /**
78
- * Transforms the value inside a Option if it exists.
79
- *
80
- * @example
81
- * ```ts
82
- * pipe(Option.some(5), Option.map(n => n * 2)); // Some(10)
83
- * pipe(Option.none(), Option.map(n => n * 2)); // None
84
- * ```
85
- */
86
- Option.map = (f) => (data) => Option.isSome(data) ? Option.some(f(data.value)) : data;
87
- /**
88
- * Chains Option computations. If the first is Some, passes the value to f.
89
- * If the first is None, propagates None.
90
- *
91
- * @example
92
- * ```ts
93
- * const parseNumber = (s: string): Option<number> => {
94
- * const n = parseInt(s, 10);
95
- * return isNaN(n) ? Option.none() : Option.some(n);
96
- * };
97
- *
98
- * pipe(Option.some("42"), Option.chain(parseNumber)); // Some(42)
99
- * pipe(Option.some("abc"), Option.chain(parseNumber)); // None
100
- * ```
101
- */
102
- Option.chain = (f) => (data) => Option.isSome(data) ? f(data.value) : data;
103
- /**
104
- * Extracts the value from a Option by providing handlers for both cases.
105
- *
106
- * @example
107
- * ```ts
108
- * pipe(
109
- * Option.some(5),
110
- * Option.fold(
111
- * () => "No value",
112
- * n => `Value: ${n}`
113
- * )
114
- * ); // "Value: 5"
115
- * ```
116
- */
117
- Option.fold = (onNone, onSome) => (data) => Option.isSome(data) ? onSome(data.value) : onNone();
118
- /**
119
- * Pattern matches on a Option, returning the result of the matching case.
120
- *
121
- * @example
122
- * ```ts
123
- * pipe(
124
- * optionUser,
125
- * Option.match({
126
- * some: user => `Hello, ${user.name}`,
127
- * none: () => "Hello, stranger"
128
- * })
129
- * );
130
- * ```
131
- */
132
- Option.match = (cases) => (data) => Option.isSome(data) ? cases.some(data.value) : cases.none();
133
- /**
134
- * Returns the value inside an Option, or a default value if None.
135
- * The default is a thunk `() => B` — evaluated only when the Option is None.
136
- * The default can be a different type, widening the result to `A | B`.
137
- *
138
- * @example
139
- * ```ts
140
- * pipe(Option.some(5), Option.getOrElse(() => 0)); // 5
141
- * pipe(Option.none(), Option.getOrElse(() => 0)); // 0
142
- * pipe(Option.none<string>(), Option.getOrElse(() => null)); // null — typed as string | null
143
- * ```
144
- */
145
- Option.getOrElse = (defaultValue) => (data) => Option.isSome(data) ? data.value : defaultValue();
146
- /**
147
- * Executes a side effect on the value without changing the Option.
148
- * Useful for logging or debugging.
149
- *
150
- * @example
151
- * ```ts
152
- * pipe(
153
- * Option.some(5),
154
- * Option.tap(n => console.log("Value:", n)),
155
- * Option.map(n => n * 2)
156
- * );
157
- * ```
158
- */
159
- Option.tap = (f) => (data) => {
160
- if (Option.isSome(data))
161
- f(data.value);
162
- return data;
163
- };
164
- /**
165
- * Filters a Option based on a predicate.
166
- * Returns None if the predicate returns false or if the Option is already None.
167
- *
168
- * @example
169
- * ```ts
170
- * pipe(Option.some(5), Option.filter(n => n > 3)); // Some(5)
171
- * pipe(Option.some(2), Option.filter(n => n > 3)); // None
172
- * ```
173
- */
174
- Option.filter = (predicate) => (data) => Option.isSome(data) ? (predicate(data.value) ? data : Option.none()) : data;
175
- /**
176
- * Recovers from a None by providing a fallback Option.
177
- * The fallback can produce a different type, widening the result to `Option<A | B>`.
178
- */
179
- Option.recover = (fallback) => (data) => Option.isSome(data) ? data : fallback();
180
- /**
181
- * Applies a function wrapped in a Option to a value wrapped in a Option.
182
- *
183
- * @example
184
- * ```ts
185
- * const add = (a: number) => (b: number) => a + b;
186
- * pipe(
187
- * Option.some(add),
188
- * Option.ap(Option.some(5)),
189
- * Option.ap(Option.some(3))
190
- * ); // Some(8)
191
- * ```
192
- */
193
- Option.ap = (arg) => (data) => Option.isSome(data) && Option.isSome(arg) ? Option.some(data.value(arg.value)) : Option.none();
194
- })(Option || (exports.Option = Option = {}));
@@ -1,163 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Optional = void 0;
4
- const Option_js_1 = require("./Option.js");
5
- var Optional;
6
- (function (Optional) {
7
- /**
8
- * Constructs an Optional from a getter (returning Option<A>) and a setter.
9
- *
10
- * @example
11
- * ```ts
12
- * const firstChar = Optional.make(
13
- * (s: string) => s.length > 0 ? Option.some(s[0]) : Option.none(),
14
- * (c) => (s) => s.length > 0 ? c + s.slice(1) : s,
15
- * );
16
- * ```
17
- */
18
- Optional.make = (get, set) => ({ get, set });
19
- /**
20
- * Creates an Optional that focuses on an optional property of an object.
21
- * Only keys whose type includes undefined (i.e. `field?: T`) are accepted.
22
- * Call with the structure type first, then the key.
23
- *
24
- * @example
25
- * ```ts
26
- * type Profile = { username: string; bio?: string };
27
- * const bioOpt = Optional.prop<Profile>()("bio");
28
- * ```
29
- */
30
- Optional.prop = () => (key) => Optional.make((s) => {
31
- const val = s[key];
32
- return val != null ? Option_js_1.Option.some(val) : Option_js_1.Option.none();
33
- }, (a) => (s) => ({ ...s, [key]: a }));
34
- /**
35
- * Creates an Optional that focuses on an element at a given index in an array.
36
- * Returns None when the index is out of bounds; set is a no-op when out of bounds.
37
- *
38
- * @example
39
- * ```ts
40
- * const firstItem = Optional.index<string>(0);
41
- *
42
- * pipe(["a", "b"], Optional.get(firstItem)); // Some("a")
43
- * pipe([], Optional.get(firstItem)); // None
44
- * ```
45
- */
46
- Optional.index = (i) => Optional.make((arr) => i >= 0 && i < arr.length ? Option_js_1.Option.some(arr[i]) : Option_js_1.Option.none(), (a) => (arr) => {
47
- if (i < 0 || i >= arr.length)
48
- return arr;
49
- const copy = [...arr];
50
- copy[i] = a;
51
- return copy;
52
- });
53
- /**
54
- * Reads the focused value from a structure, returning Option<A>.
55
- *
56
- * @example
57
- * ```ts
58
- * pipe(profile, Optional.get(bioOpt)); // Some("...") or None
59
- * ```
60
- */
61
- Optional.get = (opt) => (s) => opt.get(s);
62
- /**
63
- * Replaces the focused value within a structure.
64
- * For indexed focuses, this is a no-op when the index is out of bounds.
65
- *
66
- * @example
67
- * ```ts
68
- * pipe(profile, Optional.set(bioOpt)("hello"));
69
- * ```
70
- */
71
- Optional.set = (opt) => (a) => (s) => opt.set(a)(s);
72
- /**
73
- * Applies a function to the focused value if it is present; returns the
74
- * structure unchanged if the focus is absent.
75
- *
76
- * @example
77
- * ```ts
78
- * pipe(profile, Optional.modify(bioOpt)(s => s.toUpperCase()));
79
- * ```
80
- */
81
- Optional.modify = (opt) => (f) => (s) => {
82
- const val = opt.get(s);
83
- return val.kind === "None" ? s : opt.set(f(val.value))(s);
84
- };
85
- /**
86
- * Returns the focused value or a default when the focus is absent.
87
- *
88
- * @example
89
- * ```ts
90
- * pipe(profile, Optional.getOrElse(bioOpt)(() => "no bio"));
91
- * ```
92
- */
93
- Optional.getOrElse = (opt) => (defaultValue) => (s) => {
94
- const val = opt.get(s);
95
- return val.kind === "Some" ? val.value : defaultValue();
96
- };
97
- /**
98
- * Extracts a value from an Optional focus using handlers for the present
99
- * and absent cases.
100
- *
101
- * @example
102
- * ```ts
103
- * pipe(profile, Optional.fold(bioOpt)(() => "no bio", (bio) => bio.toUpperCase()));
104
- * ```
105
- */
106
- Optional.fold = (opt) => (onNone, onSome) => (s) => {
107
- const val = opt.get(s);
108
- return val.kind === "Some" ? onSome(val.value) : onNone();
109
- };
110
- /**
111
- * Pattern matches on an Optional focus using a named-case object.
112
- *
113
- * @example
114
- * ```ts
115
- * pipe(
116
- * profile,
117
- * Optional.match(bioOpt)({ none: () => "no bio", some: (bio) => bio }),
118
- * );
119
- * ```
120
- */
121
- Optional.match = (opt) => (cases) => (s) => {
122
- const val = opt.get(s);
123
- return val.kind === "Some" ? cases.some(val.value) : cases.none();
124
- };
125
- /**
126
- * Composes two Optionals: focuses through the outer, then through the inner.
127
- * Returns None if either focus is absent.
128
- *
129
- * @example
130
- * ```ts
131
- * const deepOpt = pipe(
132
- * Optional.prop<User>()("address"),
133
- * Optional.andThen(Optional.prop<Address>()("landmark")),
134
- * );
135
- * ```
136
- */
137
- Optional.andThen = (inner) => (outer) => Optional.make((s) => {
138
- const mid = outer.get(s);
139
- return mid.kind === "None" ? Option_js_1.Option.none() : inner.get(mid.value);
140
- }, (b) => (s) => {
141
- const mid = outer.get(s);
142
- return mid.kind === "None" ? s : outer.set(inner.set(b)(mid.value))(s);
143
- });
144
- /**
145
- * Composes an Optional with a Lens, producing an Optional.
146
- * The Lens focuses within the value found by the Optional.
147
- *
148
- * @example
149
- * ```ts
150
- * const cityOpt = pipe(
151
- * Optional.prop<User>()("address"),
152
- * Optional.andThenLens(Lens.prop<Address>()("city")),
153
- * );
154
- * ```
155
- */
156
- Optional.andThenLens = (inner) => (outer) => Optional.make((s) => {
157
- const mid = outer.get(s);
158
- return mid.kind === "None" ? Option_js_1.Option.none() : Option_js_1.Option.some(inner.get(mid.value));
159
- }, (b) => (s) => {
160
- const mid = outer.get(s);
161
- return mid.kind === "None" ? s : outer.set(inner.set(b)(mid.value))(s);
162
- });
163
- })(Optional || (exports.Optional = Optional = {}));
@@ -1,136 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Predicate = void 0;
4
- var Predicate;
5
- (function (Predicate) {
6
- /**
7
- * Negates a predicate: the result passes exactly when the original fails.
8
- *
9
- * @example
10
- * ```ts
11
- * const isBlank: Predicate<string> = s => s.trim().length === 0;
12
- * const isNotBlank = Predicate.not(isBlank);
13
- *
14
- * isNotBlank("hello"); // true
15
- * isNotBlank(" "); // false
16
- * ```
17
- */
18
- Predicate.not = (p) => (a) => !p(a);
19
- /**
20
- * Combines two predicates with logical AND: passes only when both hold.
21
- *
22
- * Data-last — the first predicate is the data being piped.
23
- *
24
- * @example
25
- * ```ts
26
- * const isPositive: Predicate<number> = n => n > 0;
27
- * const isEven: Predicate<number> = n => n % 2 === 0;
28
- *
29
- * const isPositiveEven: Predicate<number> = pipe(isPositive, Predicate.and(isEven));
30
- *
31
- * isPositiveEven(4); // true
32
- * isPositiveEven(3); // false — positive but odd
33
- * isPositiveEven(-2); // false — even but not positive
34
- * ```
35
- */
36
- Predicate.and = (second) => (first) => (a) => first(a) && second(a);
37
- /**
38
- * Combines two predicates with logical OR: passes when either holds.
39
- *
40
- * Data-last — the first predicate is the data being piped.
41
- *
42
- * @example
43
- * ```ts
44
- * const isChild: Predicate<number> = n => n < 13;
45
- * const isSenior: Predicate<number> = n => n >= 65;
46
- *
47
- * const getsDiscount: Predicate<number> = pipe(isChild, Predicate.or(isSenior));
48
- *
49
- * getsDiscount(8); // true
50
- * getsDiscount(70); // true
51
- * getsDiscount(30); // false
52
- * ```
53
- */
54
- Predicate.or = (second) => (first) => (a) => first(a) || second(a);
55
- /**
56
- * Adapts a `Predicate<A>` to work on a different input type `B` by applying `f`
57
- * to extract the relevant `A` from a `B` before running the check.
58
- *
59
- * Data-last — the predicate is the data being piped; `f` is the extractor.
60
- *
61
- * @example
62
- * ```ts
63
- * type User = { name: string; age: number };
64
- *
65
- * const isAdult: Predicate<number> = n => n >= 18;
66
- *
67
- * // Lift isAdult to work on Users by extracting the age field
68
- * const isAdultUser: Predicate<User> = pipe(
69
- * isAdult,
70
- * Predicate.using((u: User) => u.age)
71
- * );
72
- *
73
- * isAdultUser({ name: "Alice", age: 30 }); // true
74
- * isAdultUser({ name: "Bob", age: 15 }); // false
75
- * ```
76
- */
77
- Predicate.using = (f) => (p) => (b) => p(f(b));
78
- /**
79
- * Combines an array of predicates with AND: passes only when every predicate holds.
80
- * Returns `true` for an empty array (vacuous truth).
81
- *
82
- * @example
83
- * ```ts
84
- * const checks: Predicate<string>[] = [
85
- * s => s.length > 0,
86
- * s => s.length <= 100,
87
- * s => !s.includes("<"),
88
- * ];
89
- *
90
- * Predicate.all(checks)("hello"); // true
91
- * Predicate.all(checks)(""); // false — too short
92
- * Predicate.all(checks)("<b>"); // false — contains "<"
93
- * Predicate.all([])("anything"); // true
94
- * ```
95
- */
96
- Predicate.all = (predicates) => (a) => predicates.every((p) => p(a));
97
- /**
98
- * Combines an array of predicates with OR: passes when at least one holds.
99
- * Returns `false` for an empty array.
100
- *
101
- * @example
102
- * ```ts
103
- * const acceptedFormats: Predicate<string>[] = [
104
- * s => s.endsWith(".jpg"),
105
- * s => s.endsWith(".png"),
106
- * s => s.endsWith(".webp"),
107
- * ];
108
- *
109
- * Predicate.any(acceptedFormats)("photo.jpg"); // true
110
- * Predicate.any(acceptedFormats)("photo.gif"); // false
111
- * Predicate.any([])("anything"); // false
112
- * ```
113
- */
114
- Predicate.any = (predicates) => (a) => predicates.some((p) => p(a));
115
- /**
116
- * Converts a `Refinement<A, B>` into a `Predicate<A>`, discarding the compile-time
117
- * narrowing. Use this when you want to combine a type guard with plain predicates
118
- * using `and`, `or`, or `all`.
119
- *
120
- * @example
121
- * ```ts
122
- * const isString: Refinement<unknown, string> =
123
- * Refinement.make(x => typeof x === "string");
124
- *
125
- * const isShortString: Predicate<unknown> = pipe(
126
- * Predicate.fromRefinement(isString),
127
- * Predicate.and(x => (x as string).length < 10)
128
- * );
129
- *
130
- * isShortString("hi"); // true
131
- * isShortString("a very long string that exceeds ten characters"); // false
132
- * isShortString(42); // false
133
- * ```
134
- */
135
- Predicate.fromRefinement = (r) => r;
136
- })(Predicate || (exports.Predicate = Predicate = {}));
@@ -1,137 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Reader = void 0;
4
- var Reader;
5
- (function (Reader) {
6
- /**
7
- * Lifts a pure value into a Reader. The environment is ignored.
8
- *
9
- * @example
10
- * ```ts
11
- * const always42: Reader<Config, number> = Reader.resolve(42);
12
- * always42(anyConfig); // 42
13
- * ```
14
- */
15
- Reader.resolve = (value) => (_env) => value;
16
- /**
17
- * Returns the full environment as the result.
18
- * The fundamental way to access the environment in a pipeline.
19
- *
20
- * @example
21
- * ```ts
22
- * pipe(
23
- * Reader.ask<Config>(),
24
- * Reader.map(config => config.baseUrl)
25
- * )(appConfig); // "https://api.example.com"
26
- * ```
27
- */
28
- Reader.ask = () => (env) => env;
29
- /**
30
- * Projects a value from the environment using a selector function.
31
- * Equivalent to `pipe(Reader.ask(), Reader.map(f))` but more direct.
32
- *
33
- * @example
34
- * ```ts
35
- * const getBaseUrl: Reader<Config, string> = Reader.asks(c => c.baseUrl);
36
- * getBaseUrl(appConfig); // "https://api.example.com"
37
- * ```
38
- */
39
- Reader.asks = (f) => (env) => f(env);
40
- /**
41
- * Transforms the value produced by a Reader.
42
- *
43
- * @example
44
- * ```ts
45
- * pipe(
46
- * Reader.asks((c: Config) => c.baseUrl),
47
- * Reader.map(url => url.toUpperCase())
48
- * )(appConfig); // "HTTPS://API.EXAMPLE.COM"
49
- * ```
50
- */
51
- Reader.map = (f) => (data) => (env) => f(data(env));
52
- /**
53
- * Sequences two Readers. Both see the same environment.
54
- * The output of the first is passed to `f`, which returns the next Reader.
55
- *
56
- * @example
57
- * ```ts
58
- * const buildUrl = (path: string): Reader<Config, string> =>
59
- * Reader.asks(c => `${c.baseUrl}${path}`);
60
- *
61
- * const addAuth = (url: string): Reader<Config, string> =>
62
- * Reader.asks(c => `${url}?key=${c.apiKey}`);
63
- *
64
- * pipe(
65
- * buildUrl("/items"),
66
- * Reader.chain(addAuth)
67
- * )(appConfig); // "https://api.example.com/items?key=secret"
68
- * ```
69
- */
70
- Reader.chain = (f) => (data) => (env) => f(data(env))(env);
71
- /**
72
- * Applies a function wrapped in a Reader to a value wrapped in a Reader.
73
- * Both Readers see the same environment.
74
- *
75
- * @example
76
- * ```ts
77
- * const add = (a: number) => (b: number) => a + b;
78
- * pipe(
79
- * Reader.resolve<Config, typeof add>(add),
80
- * Reader.ap(Reader.asks(c => c.timeout)),
81
- * Reader.ap(Reader.resolve(5))
82
- * )(appConfig);
83
- * ```
84
- */
85
- Reader.ap = (arg) => (data) => (env) => data(env)(arg(env));
86
- /**
87
- * Executes a side effect on the produced value without changing the Reader.
88
- * Useful for logging or debugging inside a pipeline.
89
- *
90
- * @example
91
- * ```ts
92
- * pipe(
93
- * buildUrl("/users"),
94
- * Reader.tap(url => console.log("Requesting:", url)),
95
- * Reader.chain(addAuth)
96
- * )(appConfig);
97
- * ```
98
- */
99
- Reader.tap = (f) => (data) => (env) => {
100
- const a = data(env);
101
- f(a);
102
- return a;
103
- };
104
- /**
105
- * Adapts a Reader to work with a different (typically wider) environment
106
- * by transforming the environment before passing it to the Reader.
107
- * This lets you compose Readers that expect different environments.
108
- *
109
- * @example
110
- * ```ts
111
- * type AppEnv = { db: DbPool; config: Config; logger: Logger };
112
- *
113
- * // buildUrl only needs Config
114
- * const buildUrl: Reader<Config, string> = Reader.asks(c => c.baseUrl);
115
- *
116
- * // Zoom in from AppEnv to Config
117
- * const buildUrlFromApp: Reader<AppEnv, string> =
118
- * pipe(buildUrl, Reader.local((env: AppEnv) => env.config));
119
- *
120
- * buildUrlFromApp(appEnv); // works with the full AppEnv
121
- * ```
122
- */
123
- Reader.local = (f) => (data) => (env) => data(f(env));
124
- /**
125
- * Runs a Reader by supplying the environment. Use this at the edge of your
126
- * program where the environment is available.
127
- *
128
- * @example
129
- * ```ts
130
- * pipe(
131
- * buildEndpoint("/users"),
132
- * Reader.run(appConfig)
133
- * ); // "https://api.example.com/users?key=secret"
134
- * ```
135
- */
136
- Reader.run = (env) => (data) => data(env);
137
- })(Reader || (exports.Reader = Reader = {}));