@nlozgachev/pipelined 0.11.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 (193) 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/Validation.js +0 -212
  60. package/esm/src/Core/index.js +0 -17
  61. package/esm/src/Types/Brand.js +0 -28
  62. package/esm/src/Types/NonEmptyList.js +0 -14
  63. package/esm/src/Types/index.js +0 -2
  64. package/esm/src/Utils/Arr.js +0 -570
  65. package/esm/src/Utils/Num.js +0 -124
  66. package/esm/src/Utils/Rec.js +0 -215
  67. package/esm/src/Utils/Str.js +0 -134
  68. package/esm/src/Utils/index.js +0 -4
  69. package/script/mod.js +0 -19
  70. package/script/package.json +0 -3
  71. package/script/src/Composition/compose.js +0 -6
  72. package/script/src/Composition/converge.js +0 -6
  73. package/script/src/Composition/curry.js +0 -48
  74. package/script/src/Composition/flip.js +0 -24
  75. package/script/src/Composition/flow.js +0 -11
  76. package/script/src/Composition/fn.js +0 -98
  77. package/script/src/Composition/index.js +0 -29
  78. package/script/src/Composition/juxt.js +0 -6
  79. package/script/src/Composition/memoize.js +0 -71
  80. package/script/src/Composition/not.js +0 -29
  81. package/script/src/Composition/on.js +0 -16
  82. package/script/src/Composition/pipe.js +0 -6
  83. package/script/src/Composition/tap.js +0 -37
  84. package/script/src/Composition/uncurry.js +0 -38
  85. package/script/src/Core/Deferred.js +0 -33
  86. package/script/src/Core/InternalTypes.js +0 -2
  87. package/script/src/Core/Lens.js +0 -101
  88. package/script/src/Core/Logged.js +0 -114
  89. package/script/src/Core/Option.js +0 -194
  90. package/script/src/Core/Optional.js +0 -163
  91. package/script/src/Core/Predicate.js +0 -136
  92. package/script/src/Core/Reader.js +0 -137
  93. package/script/src/Core/Refinement.js +0 -118
  94. package/script/src/Core/RemoteData.js +0 -214
  95. package/script/src/Core/Result.js +0 -173
  96. package/script/src/Core/State.js +0 -184
  97. package/script/src/Core/Task.js +0 -226
  98. package/script/src/Core/TaskOption.js +0 -109
  99. package/script/src/Core/TaskResult.js +0 -130
  100. package/script/src/Core/TaskValidation.js +0 -131
  101. package/script/src/Core/These.js +0 -248
  102. package/script/src/Core/Validation.js +0 -215
  103. package/script/src/Core/index.js +0 -33
  104. package/script/src/Types/Brand.js +0 -31
  105. package/script/src/Types/NonEmptyList.js +0 -18
  106. package/script/src/Types/index.js +0 -18
  107. package/script/src/Utils/Arr.js +0 -573
  108. package/script/src/Utils/Num.js +0 -127
  109. package/script/src/Utils/Rec.js +0 -218
  110. package/script/src/Utils/Str.js +0 -137
  111. package/script/src/Utils/index.js +0 -20
  112. package/types/mod.d.ts +0 -4
  113. package/types/mod.d.ts.map +0 -1
  114. package/types/src/Composition/compose.d.ts +0 -33
  115. package/types/src/Composition/compose.d.ts.map +0 -1
  116. package/types/src/Composition/converge.d.ts +0 -21
  117. package/types/src/Composition/converge.d.ts.map +0 -1
  118. package/types/src/Composition/curry.d.ts +0 -43
  119. package/types/src/Composition/curry.d.ts.map +0 -1
  120. package/types/src/Composition/flip.d.ts +0 -21
  121. package/types/src/Composition/flip.d.ts.map +0 -1
  122. package/types/src/Composition/flow.d.ts +0 -56
  123. package/types/src/Composition/flow.d.ts.map +0 -1
  124. package/types/src/Composition/fn.d.ts +0 -76
  125. package/types/src/Composition/fn.d.ts.map +0 -1
  126. package/types/src/Composition/index.d.ts +0 -14
  127. package/types/src/Composition/index.d.ts.map +0 -1
  128. package/types/src/Composition/juxt.d.ts +0 -18
  129. package/types/src/Composition/juxt.d.ts.map +0 -1
  130. package/types/src/Composition/memoize.d.ts +0 -46
  131. package/types/src/Composition/memoize.d.ts.map +0 -1
  132. package/types/src/Composition/not.d.ts +0 -26
  133. package/types/src/Composition/not.d.ts.map +0 -1
  134. package/types/src/Composition/on.d.ts +0 -13
  135. package/types/src/Composition/on.d.ts.map +0 -1
  136. package/types/src/Composition/pipe.d.ts +0 -56
  137. package/types/src/Composition/pipe.d.ts.map +0 -1
  138. package/types/src/Composition/tap.d.ts +0 -31
  139. package/types/src/Composition/tap.d.ts.map +0 -1
  140. package/types/src/Composition/uncurry.d.ts +0 -54
  141. package/types/src/Composition/uncurry.d.ts.map +0 -1
  142. package/types/src/Core/Deferred.d.ts +0 -49
  143. package/types/src/Core/Deferred.d.ts.map +0 -1
  144. package/types/src/Core/InternalTypes.d.ts +0 -23
  145. package/types/src/Core/InternalTypes.d.ts.map +0 -1
  146. package/types/src/Core/Lens.d.ts +0 -118
  147. package/types/src/Core/Lens.d.ts.map +0 -1
  148. package/types/src/Core/Logged.d.ts +0 -126
  149. package/types/src/Core/Logged.d.ts.map +0 -1
  150. package/types/src/Core/Option.d.ts +0 -209
  151. package/types/src/Core/Option.d.ts.map +0 -1
  152. package/types/src/Core/Optional.d.ts +0 -158
  153. package/types/src/Core/Optional.d.ts.map +0 -1
  154. package/types/src/Core/Predicate.d.ts +0 -161
  155. package/types/src/Core/Predicate.d.ts.map +0 -1
  156. package/types/src/Core/Reader.d.ts +0 -156
  157. package/types/src/Core/Reader.d.ts.map +0 -1
  158. package/types/src/Core/Refinement.d.ts +0 -138
  159. package/types/src/Core/Refinement.d.ts.map +0 -1
  160. package/types/src/Core/RemoteData.d.ts +0 -197
  161. package/types/src/Core/RemoteData.d.ts.map +0 -1
  162. package/types/src/Core/Result.d.ts +0 -182
  163. package/types/src/Core/Result.d.ts.map +0 -1
  164. package/types/src/Core/State.d.ts +0 -192
  165. package/types/src/Core/State.d.ts.map +0 -1
  166. package/types/src/Core/Task.d.ts +0 -219
  167. package/types/src/Core/Task.d.ts.map +0 -1
  168. package/types/src/Core/TaskOption.d.ts +0 -121
  169. package/types/src/Core/TaskOption.d.ts.map +0 -1
  170. package/types/src/Core/TaskResult.d.ts +0 -119
  171. package/types/src/Core/TaskResult.d.ts.map +0 -1
  172. package/types/src/Core/TaskValidation.d.ts +0 -144
  173. package/types/src/Core/TaskValidation.d.ts.map +0 -1
  174. package/types/src/Core/These.d.ts +0 -225
  175. package/types/src/Core/These.d.ts.map +0 -1
  176. package/types/src/Core/Validation.d.ts +0 -203
  177. package/types/src/Core/Validation.d.ts.map +0 -1
  178. package/types/src/Core/index.d.ts +0 -18
  179. package/types/src/Core/index.d.ts.map +0 -1
  180. package/types/src/Types/Brand.d.ts.map +0 -1
  181. package/types/src/Types/NonEmptyList.d.ts.map +0 -1
  182. package/types/src/Types/index.d.ts +0 -3
  183. package/types/src/Types/index.d.ts.map +0 -1
  184. package/types/src/Utils/Arr.d.ts +0 -403
  185. package/types/src/Utils/Arr.d.ts.map +0 -1
  186. package/types/src/Utils/Num.d.ts +0 -110
  187. package/types/src/Utils/Num.d.ts.map +0 -1
  188. package/types/src/Utils/Rec.d.ts +0 -143
  189. package/types/src/Utils/Rec.d.ts.map +0 -1
  190. package/types/src/Utils/Str.d.ts +0 -128
  191. package/types/src/Utils/Str.d.ts.map +0 -1
  192. package/types/src/Utils/index.d.ts +0 -5
  193. package/types/src/Utils/index.d.ts.map +0 -1
@@ -1,245 +0,0 @@
1
- export var These;
2
- (function (These) {
3
- /**
4
- * Creates a These holding only a first value.
5
- *
6
- * @example
7
- * ```ts
8
- * These.first(42); // { kind: "First", first: 42 }
9
- * ```
10
- */
11
- These.first = (value) => ({ kind: "First", first: value });
12
- /**
13
- * Creates a These holding only a second value.
14
- *
15
- * @example
16
- * ```ts
17
- * These.second("warning"); // { kind: "Second", second: "warning" }
18
- * ```
19
- */
20
- These.second = (value) => ({ kind: "Second", second: value });
21
- /**
22
- * Creates a These holding both a first and a second value simultaneously.
23
- *
24
- * @example
25
- * ```ts
26
- * These.both(42, "Deprecated API used"); // { kind: "Both", first: 42, second: "Deprecated API used" }
27
- * ```
28
- */
29
- These.both = (first, second) => ({
30
- kind: "Both",
31
- first,
32
- second,
33
- });
34
- /**
35
- * Type guard — checks if a These holds only a first value.
36
- */
37
- These.isFirst = (data) => data.kind === "First";
38
- /**
39
- * Type guard — checks if a These holds only a second value.
40
- */
41
- These.isSecond = (data) => data.kind === "Second";
42
- /**
43
- * Type guard — checks if a These holds both values simultaneously.
44
- */
45
- These.isBoth = (data) => data.kind === "Both";
46
- /**
47
- * Returns true if the These contains a first value (First or Both).
48
- */
49
- These.hasFirst = (data) => data.kind === "First" || data.kind === "Both";
50
- /**
51
- * Returns true if the These contains a second value (Second or Both).
52
- */
53
- These.hasSecond = (data) => data.kind === "Second" || data.kind === "Both";
54
- /**
55
- * Transforms the first value, leaving the second unchanged.
56
- *
57
- * @example
58
- * ```ts
59
- * pipe(These.first(5), These.mapFirst(n => n * 2)); // First(10)
60
- * pipe(These.both(5, "warn"), These.mapFirst(n => n * 2)); // Both(10, "warn")
61
- * pipe(These.second("warn"), These.mapFirst(n => n * 2)); // Second("warn")
62
- * ```
63
- */
64
- These.mapFirst = (f) => (data) => {
65
- if (These.isSecond(data))
66
- return data;
67
- if (These.isFirst(data))
68
- return These.first(f(data.first));
69
- return These.both(f(data.first), data.second);
70
- };
71
- /**
72
- * Transforms the second value, leaving the first unchanged.
73
- *
74
- * @example
75
- * ```ts
76
- * pipe(These.second("warn"), These.mapSecond(e => e.toUpperCase())); // Second("WARN")
77
- * pipe(These.both(5, "warn"), These.mapSecond(e => e.toUpperCase())); // Both(5, "WARN")
78
- * ```
79
- */
80
- These.mapSecond = (f) => (data) => {
81
- if (These.isFirst(data))
82
- return data;
83
- if (These.isSecond(data))
84
- return These.second(f(data.second));
85
- return These.both(data.first, f(data.second));
86
- };
87
- /**
88
- * Transforms both the first and second values independently.
89
- *
90
- * @example
91
- * ```ts
92
- * pipe(
93
- * These.both(5, "warn"),
94
- * These.mapBoth(n => n * 2, e => e.toUpperCase())
95
- * ); // Both(10, "WARN")
96
- * ```
97
- */
98
- These.mapBoth = (onFirst, onSecond) => (data) => {
99
- if (These.isSecond(data))
100
- return These.second(onSecond(data.second));
101
- if (These.isFirst(data))
102
- return These.first(onFirst(data.first));
103
- return These.both(onFirst(data.first), onSecond(data.second));
104
- };
105
- /**
106
- * Chains These computations by passing the first value to f.
107
- * Second propagates unchanged; First and Both apply f to the first value.
108
- *
109
- * @example
110
- * ```ts
111
- * const double = (n: number): These<number, string> => These.first(n * 2);
112
- *
113
- * pipe(These.first(5), These.chainFirst(double)); // First(10)
114
- * pipe(These.both(5, "warn"), These.chainFirst(double)); // First(10)
115
- * pipe(These.second("warn"), These.chainFirst(double)); // Second("warn")
116
- * ```
117
- */
118
- These.chainFirst = (f) => (data) => {
119
- if (These.isSecond(data))
120
- return data;
121
- return f(data.first);
122
- };
123
- /**
124
- * Chains These computations by passing the second value to f.
125
- * First propagates unchanged; Second and Both apply f to the second value.
126
- *
127
- * @example
128
- * ```ts
129
- * const shout = (s: string): These<number, string> => These.second(s.toUpperCase());
130
- *
131
- * pipe(These.second("warn"), These.chainSecond(shout)); // Second("WARN")
132
- * pipe(These.both(5, "warn"), These.chainSecond(shout)); // Second("WARN")
133
- * pipe(These.first(5), These.chainSecond(shout)); // First(5)
134
- * ```
135
- */
136
- These.chainSecond = (f) => (data) => {
137
- if (These.isFirst(data))
138
- return data;
139
- return f(data.second);
140
- };
141
- /**
142
- * Extracts a value from a These by providing handlers for all three cases.
143
- *
144
- * @example
145
- * ```ts
146
- * pipe(
147
- * these,
148
- * These.fold(
149
- * a => `First: ${a}`,
150
- * b => `Second: ${b}`,
151
- * (a, b) => `Both: ${a} / ${b}`
152
- * )
153
- * );
154
- * ```
155
- */
156
- These.fold = (onFirst, onSecond, onBoth) => (data) => {
157
- if (These.isSecond(data))
158
- return onSecond(data.second);
159
- if (These.isFirst(data))
160
- return onFirst(data.first);
161
- return onBoth(data.first, data.second);
162
- };
163
- /**
164
- * Pattern matches on a These, returning the result of the matching case.
165
- *
166
- * @example
167
- * ```ts
168
- * pipe(
169
- * these,
170
- * These.match({
171
- * first: a => `First: ${a}`,
172
- * second: b => `Second: ${b}`,
173
- * both: (a, b) => `Both: ${a} / ${b}`
174
- * })
175
- * );
176
- * ```
177
- */
178
- These.match = (cases) => (data) => {
179
- if (These.isSecond(data))
180
- return cases.second(data.second);
181
- if (These.isFirst(data))
182
- return cases.first(data.first);
183
- return cases.both(data.first, data.second);
184
- };
185
- /**
186
- * Returns the first value, or a default if the These has no first value.
187
- * The default can be a different type, widening the result to `A | C`.
188
- *
189
- * @example
190
- * ```ts
191
- * pipe(These.first(5), These.getFirstOrElse(() => 0)); // 5
192
- * pipe(These.both(5, "warn"), These.getFirstOrElse(() => 0)); // 5
193
- * pipe(These.second("warn"), These.getFirstOrElse(() => 0)); // 0
194
- * pipe(These.second("warn"), These.getFirstOrElse(() => null)); // null — typed as number | null
195
- * ```
196
- */
197
- These.getFirstOrElse = (defaultValue) => (data) => These.hasFirst(data) ? data.first : defaultValue();
198
- /**
199
- * Returns the second value, or a default if the These has no second value.
200
- * The default can be a different type, widening the result to `B | D`.
201
- *
202
- * @example
203
- * ```ts
204
- * pipe(These.second("warn"), These.getSecondOrElse(() => "none")); // "warn"
205
- * pipe(These.both(5, "warn"), These.getSecondOrElse(() => "none")); // "warn"
206
- * pipe(These.first(5), These.getSecondOrElse(() => "none")); // "none"
207
- * pipe(These.first(5), These.getSecondOrElse(() => null)); // null — typed as string | null
208
- * ```
209
- */
210
- These.getSecondOrElse = (defaultValue) => (data) => These.hasSecond(data) ? data.second : defaultValue();
211
- /**
212
- * Executes a side effect on the first value without changing the These.
213
- * Useful for logging or debugging.
214
- *
215
- * @example
216
- * ```ts
217
- * pipe(These.first(5), These.tap(console.log)); // logs 5, returns First(5)
218
- * ```
219
- */
220
- These.tap = (f) => (data) => {
221
- if (These.hasFirst(data))
222
- f(data.first);
223
- return data;
224
- };
225
- /**
226
- * Swaps the roles of first and second values.
227
- * - First(a) → Second(a)
228
- * - Second(b) → First(b)
229
- * - Both(a, b) → Both(b, a)
230
- *
231
- * @example
232
- * ```ts
233
- * These.swap(These.first(5)); // Second(5)
234
- * These.swap(These.second("warn")); // First("warn")
235
- * These.swap(These.both(5, "warn")); // Both("warn", 5)
236
- * ```
237
- */
238
- These.swap = (data) => {
239
- if (These.isSecond(data))
240
- return These.first(data.second);
241
- if (These.isFirst(data))
242
- return These.second(data.first);
243
- return These.both(data.second, data.first);
244
- };
245
- })(These || (These = {}));
@@ -1,212 +0,0 @@
1
- export var Validation;
2
- (function (Validation) {
3
- /**
4
- * Wraps a value in a valid Validation.
5
- *
6
- * @example
7
- * ```ts
8
- * Validation.valid(42); // Valid(42)
9
- * ```
10
- */
11
- Validation.valid = (value) => ({
12
- kind: "Valid",
13
- value,
14
- });
15
- /**
16
- * Creates an invalid Validation from a single error.
17
- *
18
- * @example
19
- * ```ts
20
- * Validation.invalid("Invalid input");
21
- * ```
22
- */
23
- Validation.invalid = (error) => ({
24
- kind: "Invalid",
25
- errors: [error],
26
- });
27
- /**
28
- * Creates an invalid Validation from multiple errors.
29
- *
30
- * @example
31
- * ```ts
32
- * Validation.invalidAll(["Invalid input"]);
33
- * ```
34
- */
35
- Validation.invalidAll = (errors) => ({
36
- kind: "Invalid",
37
- errors,
38
- });
39
- /**
40
- * Type guard that checks if a Validation is valid.
41
- */
42
- Validation.isValid = (data) => data.kind === "Valid";
43
- /**
44
- * Type guard that checks if a Validation is invalid.
45
- */
46
- Validation.isInvalid = (data) => data.kind === "Invalid";
47
- /**
48
- * Transforms the success value inside a Validation.
49
- *
50
- * @example
51
- * ```ts
52
- * pipe(Validation.valid(5), Validation.map(n => n * 2)); // Valid(10)
53
- * pipe(Validation.invalid("oops"), Validation.map(n => n * 2)); // Invalid(["oops"])
54
- * ```
55
- */
56
- Validation.map = (f) => (data) => Validation.isValid(data) ? Validation.valid(f(data.value)) : data;
57
- /**
58
- * Applies a function wrapped in a Validation to a value wrapped in a Validation.
59
- * Accumulates errors from both sides.
60
- *
61
- * @example
62
- * ```ts
63
- * const add = (a: number) => (b: number) => a + b;
64
- * pipe(
65
- * Validation.valid(add),
66
- * Validation.ap(Validation.valid(5)),
67
- * Validation.ap(Validation.valid(3))
68
- * ); // Valid(8)
69
- *
70
- * pipe(
71
- * Validation.valid(add),
72
- * Validation.ap(Validation.invalid<string, number>("bad a")),
73
- * Validation.ap(Validation.invalid<string, number>("bad b"))
74
- * ); // Invalid(["bad a", "bad b"])
75
- * ```
76
- */
77
- Validation.ap = (arg) => (data) => {
78
- if (Validation.isValid(data) && Validation.isValid(arg))
79
- return Validation.valid(data.value(arg.value));
80
- const errors = [
81
- ...(Validation.isInvalid(data) ? data.errors : []),
82
- ...(Validation.isInvalid(arg) ? arg.errors : []),
83
- ];
84
- return Validation.invalidAll(errors);
85
- };
86
- /**
87
- * Extracts the value from a Validation by providing handlers for both cases.
88
- *
89
- * @example
90
- * ```ts
91
- * pipe(
92
- * Validation.valid(42),
93
- * Validation.fold(
94
- * errors => `Errors: ${errors.join(", ")}`,
95
- * value => `Value: ${value}`
96
- * )
97
- * );
98
- * ```
99
- */
100
- Validation.fold = (onInvalid, onValid) => (data) => Validation.isValid(data) ? onValid(data.value) : onInvalid(data.errors);
101
- /**
102
- * Pattern matches on a Validation, returning the result of the matching case.
103
- *
104
- * @example
105
- * ```ts
106
- * pipe(
107
- * validation,
108
- * Validation.match({
109
- * valid: value => `Got ${value}`,
110
- * invalid: errors => `Failed: ${errors.join(", ")}`
111
- * })
112
- * );
113
- * ```
114
- */
115
- Validation.match = (cases) => (data) => Validation.isValid(data) ? cases.valid(data.value) : cases.invalid(data.errors);
116
- /**
117
- * Returns the success value or a default value if the Validation is invalid.
118
- * The default can be a different type, widening the result to `A | B`.
119
- *
120
- * @example
121
- * ```ts
122
- * pipe(Validation.valid(5), Validation.getOrElse(() => 0)); // 5
123
- * pipe(Validation.invalid("oops"), Validation.getOrElse(() => 0)); // 0
124
- * pipe(Validation.invalid("oops"), Validation.getOrElse(() => null)); // null — typed as number | null
125
- * ```
126
- */
127
- Validation.getOrElse = (defaultValue) => (data) => Validation.isValid(data) ? data.value : defaultValue();
128
- /**
129
- * Executes a side effect on the success value without changing the Validation.
130
- *
131
- * @example
132
- * ```ts
133
- * pipe(
134
- * Validation.valid(5),
135
- * Validation.tap(n => console.log("Value:", n)),
136
- * Validation.map(n => n * 2)
137
- * );
138
- * ```
139
- */
140
- Validation.tap = (f) => (data) => {
141
- if (Validation.isValid(data))
142
- f(data.value);
143
- return data;
144
- };
145
- /**
146
- * Recovers from an Invalid state by providing a fallback Validation.
147
- * The fallback receives the accumulated error list so callers can inspect which errors occurred.
148
- * The fallback can produce a different success type, widening the result to `Validation<E, A | B>`.
149
- */
150
- Validation.recover = (fallback) => (data) => Validation.isValid(data) ? data : fallback(data.errors);
151
- /**
152
- * Recovers from an Invalid state unless the errors contain any of the blocked errors.
153
- * The fallback can produce a different success type, widening the result to `Validation<E, A | B>`.
154
- */
155
- Validation.recoverUnless = (blockedErrors, fallback) => (data) => Validation.isInvalid(data) &&
156
- !data.errors.some((err) => blockedErrors.includes(err))
157
- ? fallback()
158
- : data;
159
- /**
160
- * Combines two independent Validation instances into a tuple.
161
- * If both are Valid, returns Valid with both values as a tuple.
162
- * If either is Invalid, accumulates errors from both sides.
163
- *
164
- * @example
165
- * ```ts
166
- * Validation.product(
167
- * Validation.valid("alice"),
168
- * Validation.valid(30)
169
- * ); // Valid(["alice", 30])
170
- *
171
- * Validation.product(
172
- * Validation.invalid("Name required"),
173
- * Validation.invalid("Age must be >= 0")
174
- * ); // Invalid(["Name required", "Age must be >= 0"])
175
- * ```
176
- */
177
- Validation.product = (first, second) => {
178
- if (Validation.isValid(first) && Validation.isValid(second))
179
- return Validation.valid([first.value, second.value]);
180
- const errors = [
181
- ...(Validation.isInvalid(first) ? first.errors : []),
182
- ...(Validation.isInvalid(second) ? second.errors : []),
183
- ];
184
- return Validation.invalidAll(errors);
185
- };
186
- /**
187
- * Combines a non-empty list of Validation instances, accumulating all errors.
188
- * If all are Valid, returns Valid with all values collected into an array.
189
- * If any are Invalid, returns Invalid with all accumulated errors.
190
- *
191
- * @example
192
- * ```ts
193
- * Validation.productAll([
194
- * validateName(name),
195
- * validateEmail(email),
196
- * validateAge(age)
197
- * ]);
198
- * // Valid([name, email, age]) or Invalid([...all errors])
199
- * ```
200
- */
201
- Validation.productAll = (data) => {
202
- const values = [];
203
- const errors = [];
204
- for (const v of data) {
205
- if (Validation.isValid(v))
206
- values.push(v.value);
207
- else
208
- errors.push(...v.errors);
209
- }
210
- return errors.length > 0 ? Validation.invalidAll(errors) : Validation.valid(values);
211
- };
212
- })(Validation || (Validation = {}));
@@ -1,17 +0,0 @@
1
- export * from "./Logged.js";
2
- export * from "./Deferred.js";
3
- export * from "./Lens.js";
4
- export * from "./Option.js";
5
- export * from "./Reader.js";
6
- export * from "./Optional.js";
7
- export * from "./Predicate.js";
8
- export * from "./Refinement.js";
9
- export * from "./RemoteData.js";
10
- export * from "./State.js";
11
- export * from "./Result.js";
12
- export * from "./Task.js";
13
- export * from "./TaskOption.js";
14
- export * from "./TaskResult.js";
15
- export * from "./TaskValidation.js";
16
- export * from "./These.js";
17
- export * from "./Validation.js";
@@ -1,28 +0,0 @@
1
- export var Brand;
2
- (function (Brand) {
3
- /**
4
- * Returns a constructor that wraps a value of type T in brand K.
5
- * The resulting function performs an unchecked cast — only use when the raw
6
- * value is known to satisfy the brand's invariants.
7
- *
8
- * @example
9
- * ```ts
10
- * type PositiveNumber = Brand<"PositiveNumber", number>;
11
- * const toPositiveNumber = Brand.wrap<"PositiveNumber", number>();
12
- *
13
- * const n: PositiveNumber = toPositiveNumber(42);
14
- * ```
15
- */
16
- Brand.wrap = () => (value) => value;
17
- /**
18
- * Strips the brand and returns the underlying value.
19
- * Since Brand<K, T> extends T this is rarely needed, but can improve readability.
20
- *
21
- * @example
22
- * ```ts
23
- * const userId: UserId = toUserId("user-123");
24
- * const raw: string = Brand.unwrap(userId); // "user-123"
25
- * ```
26
- */
27
- Brand.unwrap = (branded) => branded;
28
- })(Brand || (Brand = {}));
@@ -1,14 +0,0 @@
1
- /**
2
- * Type guard that checks if an array is non-empty.
3
- *
4
- * @example
5
- * ```ts
6
- * const items: string[] = getItems();
7
- *
8
- * if (isNonEmptyList(items)) {
9
- * // TypeScript knows items has at least one element
10
- * const first = items[0]; // string, not string | undefined
11
- * }
12
- * ```
13
- */
14
- export const isNonEmptyList = (list) => list.length > 0;
@@ -1,2 +0,0 @@
1
- export * from "./Brand.js";
2
- export * from "./NonEmptyList.js";