@nlozgachev/pipekit 0.2.0 → 0.4.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 (54) hide show
  1. package/README.md +18 -13
  2. package/esm/src/Composition/flip.js +2 -2
  3. package/esm/src/Composition/fn.js +1 -1
  4. package/esm/src/Composition/tap.js +1 -1
  5. package/esm/src/Core/Arr.js +4 -4
  6. package/esm/src/Core/Option.js +13 -22
  7. package/esm/src/Core/RemoteData.js +9 -13
  8. package/esm/src/Core/Result.js +12 -21
  9. package/esm/src/Core/Task.js +26 -23
  10. package/esm/src/Core/TaskOption.js +8 -6
  11. package/esm/src/Core/TaskResult.js +10 -6
  12. package/esm/src/Core/TaskValidation.js +12 -8
  13. package/esm/src/Core/These.js +122 -123
  14. package/esm/src/Core/Validation.js +42 -43
  15. package/package.json +1 -1
  16. package/script/src/Composition/flip.js +2 -2
  17. package/script/src/Composition/fn.js +1 -1
  18. package/script/src/Composition/tap.js +1 -1
  19. package/script/src/Core/Arr.js +4 -4
  20. package/script/src/Core/Option.js +13 -22
  21. package/script/src/Core/RemoteData.js +9 -13
  22. package/script/src/Core/Result.js +12 -21
  23. package/script/src/Core/Task.js +26 -23
  24. package/script/src/Core/TaskOption.js +8 -6
  25. package/script/src/Core/TaskResult.js +10 -6
  26. package/script/src/Core/TaskValidation.js +12 -8
  27. package/script/src/Core/These.js +122 -123
  28. package/script/src/Core/Validation.js +42 -43
  29. package/types/src/Composition/flip.d.ts +2 -2
  30. package/types/src/Composition/fn.d.ts +1 -1
  31. package/types/src/Composition/pipe.d.ts +1 -1
  32. package/types/src/Composition/tap.d.ts +1 -1
  33. package/types/src/Composition/uncurry.d.ts +3 -3
  34. package/types/src/Core/Arr.d.ts +4 -4
  35. package/types/src/Core/InternalTypes.d.ts +6 -0
  36. package/types/src/Core/InternalTypes.d.ts.map +1 -1
  37. package/types/src/Core/Option.d.ts +14 -23
  38. package/types/src/Core/Option.d.ts.map +1 -1
  39. package/types/src/Core/RemoteData.d.ts +9 -13
  40. package/types/src/Core/RemoteData.d.ts.map +1 -1
  41. package/types/src/Core/Result.d.ts +12 -21
  42. package/types/src/Core/Result.d.ts.map +1 -1
  43. package/types/src/Core/Task.d.ts +35 -32
  44. package/types/src/Core/Task.d.ts.map +1 -1
  45. package/types/src/Core/TaskOption.d.ts +1 -1
  46. package/types/src/Core/TaskOption.d.ts.map +1 -1
  47. package/types/src/Core/TaskResult.d.ts +1 -1
  48. package/types/src/Core/TaskResult.d.ts.map +1 -1
  49. package/types/src/Core/TaskValidation.d.ts +10 -6
  50. package/types/src/Core/TaskValidation.d.ts.map +1 -1
  51. package/types/src/Core/These.d.ts +108 -100
  52. package/types/src/Core/These.d.ts.map +1 -1
  53. package/types/src/Core/Validation.d.ts +38 -42
  54. package/types/src/Core/Validation.d.ts.map +1 -1
@@ -1,134 +1,145 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.These = void 0;
4
- const Result_js_1 = require("./Result.js");
5
4
  var These;
6
5
  (function (These) {
7
6
  /**
8
- * Creates a These holding only an error/warning (no success value).
7
+ * Creates a These holding only a first value.
9
8
  *
10
9
  * @example
11
10
  * ```ts
12
- * These.err("Something went wrong");
11
+ * These.first(42); // { kind: "First", first: 42 }
13
12
  * ```
14
13
  */
15
- These.err = (error) => Result_js_1.Result.err(error);
14
+ These.first = (value) => ({ kind: "First", first: value });
16
15
  /**
17
- * Creates a These holding only a success value (no error).
16
+ * Creates a These holding only a second value.
18
17
  *
19
18
  * @example
20
19
  * ```ts
21
- * These.ok(42);
20
+ * These.second("warning"); // { kind: "Second", second: "warning" }
22
21
  * ```
23
22
  */
24
- These.ok = (value) => Result_js_1.Result.ok(value);
23
+ These.second = (value) => ({ kind: "Second", second: value });
25
24
  /**
26
- * Creates a These holding both an error/warning and a success value.
25
+ * Creates a These holding both a first and a second value simultaneously.
27
26
  *
28
27
  * @example
29
28
  * ```ts
30
- * These.both("Deprecated API used", result);
29
+ * These.both(42, "Deprecated API used"); // { kind: "Both", first: 42, second: "Deprecated API used" }
31
30
  * ```
32
31
  */
33
- These.both = (error, value) => ({
32
+ These.both = (first, second) => ({
34
33
  kind: "Both",
35
- error,
36
- value,
34
+ first,
35
+ second,
37
36
  });
38
37
  /**
39
- * Type guard — checks if a These holds only an error/warning.
38
+ * Type guard — checks if a These holds only a first value.
40
39
  */
41
- These.isErr = (data) => data.kind === "Error";
40
+ These.isFirst = (data) => data.kind === "First";
42
41
  /**
43
- * Type guard — checks if a These holds only a success value.
42
+ * Type guard — checks if a These holds only a second value.
44
43
  */
45
- These.isOk = (data) => data.kind === "Ok";
44
+ These.isSecond = (data) => data.kind === "Second";
46
45
  /**
47
- * Type guard — checks if a These holds both an error/warning and a success value.
46
+ * Type guard — checks if a These holds both values simultaneously.
48
47
  */
49
48
  These.isBoth = (data) => data.kind === "Both";
50
49
  /**
51
- * Returns true if the These contains a success value (Ok or Both).
50
+ * Returns true if the These contains a first value (First or Both).
52
51
  */
53
- These.hasValue = (data) => data.kind === "Ok" || data.kind === "Both";
52
+ These.hasFirst = (data) => data.kind === "First" || data.kind === "Both";
54
53
  /**
55
- * Returns true if the These contains an error/warning (Err or Both).
54
+ * Returns true if the These contains a second value (Second or Both).
56
55
  */
57
- These.hasError = (data) => data.kind === "Error" || data.kind === "Both";
56
+ These.hasSecond = (data) => data.kind === "Second" || data.kind === "Both";
58
57
  /**
59
- * Transforms the success value, leaving the error unchanged.
58
+ * Transforms the first value, leaving the second unchanged.
60
59
  *
61
60
  * @example
62
61
  * ```ts
63
- * pipe(These.ok(5), These.map(n => n * 2)); // Ok(10)
64
- * pipe(These.both("warn", 5), These.map(n => n * 2)); // Both("warn", 10)
65
- * pipe(These.err("err"), These.map(n => n * 2)); // Err("err")
62
+ * pipe(These.first(5), These.mapFirst(n => n * 2)); // First(10)
63
+ * pipe(These.both(5, "warn"), These.mapFirst(n => n * 2)); // Both(10, "warn")
64
+ * pipe(These.second("warn"), These.mapFirst(n => n * 2)); // Second("warn")
66
65
  * ```
67
66
  */
68
- These.map = (f) => (data) => {
69
- if (These.isErr(data))
67
+ These.mapFirst = (f) => (data) => {
68
+ if (These.isSecond(data))
70
69
  return data;
71
- if (These.isOk(data))
72
- return These.ok(f(data.value));
73
- return These.both(data.error, f(data.value));
70
+ if (These.isFirst(data))
71
+ return These.first(f(data.first));
72
+ return These.both(f(data.first), data.second);
74
73
  };
75
74
  /**
76
- * Transforms the error/warning value, leaving the success value unchanged.
75
+ * Transforms the second value, leaving the first unchanged.
77
76
  *
78
77
  * @example
79
78
  * ```ts
80
- * pipe(These.err("err"), These.mapErr(e => e.toUpperCase())); // Err("ERR")
81
- * pipe(These.both("warn", 5), These.mapErr(e => e.toUpperCase())); // Both("WARN", 5)
79
+ * pipe(These.second("warn"), These.mapSecond(e => e.toUpperCase())); // Second("WARN")
80
+ * pipe(These.both(5, "warn"), These.mapSecond(e => e.toUpperCase())); // Both(5, "WARN")
82
81
  * ```
83
82
  */
84
- These.mapErr = (f) => (data) => {
85
- if (These.isOk(data))
83
+ These.mapSecond = (f) => (data) => {
84
+ if (These.isFirst(data))
86
85
  return data;
87
- if (These.isErr(data))
88
- return These.err(f(data.error));
89
- return These.both(f(data.error), data.value);
86
+ if (These.isSecond(data))
87
+ return These.second(f(data.second));
88
+ return These.both(data.first, f(data.second));
90
89
  };
91
90
  /**
92
- * Transforms both the error and success values independently.
91
+ * Transforms both the first and second values independently.
93
92
  *
94
93
  * @example
95
94
  * ```ts
96
95
  * pipe(
97
- * These.both("warn", 5),
98
- * These.bimap(e => e.toUpperCase(), n => n * 2)
99
- * ); // Both("WARN", 10)
96
+ * These.both(5, "warn"),
97
+ * These.mapBoth(n => n * 2, e => e.toUpperCase())
98
+ * ); // Both(10, "WARN")
100
99
  * ```
101
100
  */
102
- These.bimap = (onErr, onOk) => (data) => {
103
- if (These.isErr(data))
104
- return These.err(onErr(data.error));
105
- if (These.isOk(data))
106
- return These.ok(onOk(data.value));
107
- return These.both(onErr(data.error), onOk(data.value));
101
+ These.mapBoth = (onFirst, onSecond) => (data) => {
102
+ if (These.isSecond(data))
103
+ return These.second(onSecond(data.second));
104
+ if (These.isFirst(data))
105
+ return These.first(onFirst(data.first));
106
+ return These.both(onFirst(data.first), onSecond(data.second));
108
107
  };
109
108
  /**
110
- * Chains These computations by passing the success value to f.
111
- * - Err propagates unchanged.
112
- * - Ok(a) applies f(a) directly.
113
- * - Both(e, a): applies f(a); if the result is Ok(b), returns Both(e, b)
114
- * to preserve the warning. Otherwise returns f(a) as-is.
109
+ * Chains These computations by passing the first value to f.
110
+ * Second propagates unchanged; First and Both apply f to the first value.
115
111
  *
116
112
  * @example
117
113
  * ```ts
118
- * const double = (n: number): These<string, number> => These.ok(n * 2);
114
+ * const double = (n: number): These<number, string> => These.first(n * 2);
119
115
  *
120
- * pipe(These.ok(5), These.chain(double)); // Ok(10)
121
- * pipe(These.both("warn", 5), These.chain(double)); // Both("warn", 10)
122
- * pipe(These.err("err"), These.chain(double)); // Err("err")
116
+ * pipe(These.first(5), These.chainFirst(double)); // First(10)
117
+ * pipe(These.both(5, "warn"), These.chainFirst(double)); // First(10)
118
+ * pipe(These.second("warn"), These.chainFirst(double)); // Second("warn")
123
119
  * ```
124
120
  */
125
- These.chain = (f) => (data) => {
126
- if (These.isErr(data))
121
+ These.chainFirst = (f) => (data) => {
122
+ if (These.isSecond(data))
127
123
  return data;
128
- if (These.isOk(data))
129
- return f(data.value);
130
- const result = f(data.value);
131
- return These.isOk(result) ? These.both(data.error, result.value) : result;
124
+ return f(data.first);
125
+ };
126
+ /**
127
+ * Chains These computations by passing the second value to f.
128
+ * First propagates unchanged; Second and Both apply f to the second value.
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * const shout = (s: string): These<number, string> => These.second(s.toUpperCase());
133
+ *
134
+ * pipe(These.second("warn"), These.chainSecond(shout)); // Second("WARN")
135
+ * pipe(These.both(5, "warn"), These.chainSecond(shout)); // Second("WARN")
136
+ * pipe(These.first(5), These.chainSecond(shout)); // First(5)
137
+ * ```
138
+ */
139
+ These.chainSecond = (f) => (data) => {
140
+ if (These.isFirst(data))
141
+ return data;
142
+ return f(data.second);
132
143
  };
133
144
  /**
134
145
  * Extracts a value from a These by providing handlers for all three cases.
@@ -138,19 +149,19 @@ var These;
138
149
  * pipe(
139
150
  * these,
140
151
  * These.fold(
141
- * e => `Error: ${e}`,
142
- * a => `Value: ${a}`,
143
- * (e, a) => `Both: ${e} / ${a}`
152
+ * a => `First: ${a}`,
153
+ * b => `Second: ${b}`,
154
+ * (a, b) => `Both: ${a} / ${b}`
144
155
  * )
145
156
  * );
146
157
  * ```
147
158
  */
148
- These.fold = (onErr, onOk, onBoth) => (data) => {
149
- if (These.isErr(data))
150
- return onErr(data.error);
151
- if (These.isOk(data))
152
- return onOk(data.value);
153
- return onBoth(data.error, data.value);
159
+ These.fold = (onFirst, onSecond, onBoth) => (data) => {
160
+ if (These.isSecond(data))
161
+ return onSecond(data.second);
162
+ if (These.isFirst(data))
163
+ return onFirst(data.first);
164
+ return onBoth(data.first, data.second);
154
165
  };
155
166
  /**
156
167
  * Pattern matches on a These, returning the result of the matching case.
@@ -160,86 +171,74 @@ var These;
160
171
  * pipe(
161
172
  * these,
162
173
  * These.match({
163
- * err: e => `Error: ${e}`,
164
- * ok: a => `Value: ${a}`,
165
- * both: (e, a) => `Both: ${e} / ${a}`
174
+ * first: a => `First: ${a}`,
175
+ * second: b => `Second: ${b}`,
176
+ * both: (a, b) => `Both: ${a} / ${b}`
166
177
  * })
167
178
  * );
168
179
  * ```
169
180
  */
170
181
  These.match = (cases) => (data) => {
171
- if (These.isErr(data))
172
- return cases.err(data.error);
173
- if (These.isOk(data))
174
- return cases.ok(data.value);
175
- return cases.both(data.error, data.value);
182
+ if (These.isSecond(data))
183
+ return cases.second(data.second);
184
+ if (These.isFirst(data))
185
+ return cases.first(data.first);
186
+ return cases.both(data.first, data.second);
176
187
  };
177
188
  /**
178
- * Returns the success value, or a default if the These has no success value.
189
+ * Returns the first value, or a default if the These has no first value.
179
190
  *
180
191
  * @example
181
192
  * ```ts
182
- * pipe(These.ok(5), These.getOrElse(0)); // 5
183
- * pipe(These.both("warn", 5), These.getOrElse(0)); // 5
184
- * pipe(These.err("err"), These.getOrElse(0)); // 0
193
+ * pipe(These.first(5), These.getFirstOrElse(0)); // 5
194
+ * pipe(These.both(5, "warn"), These.getFirstOrElse(0)); // 5
195
+ * pipe(These.second("warn"), These.getFirstOrElse(0)); // 0
185
196
  * ```
186
197
  */
187
- These.getOrElse = (defaultValue) => (data) => These.hasValue(data) ? data.value : defaultValue;
198
+ These.getFirstOrElse = (defaultValue) => (data) => These.hasFirst(data) ? data.first : defaultValue;
188
199
  /**
189
- * Executes a side effect on the success value without changing the These.
190
- * Useful for logging or debugging.
191
- */
192
- These.tap = (f) => (data) => {
193
- if (These.hasValue(data))
194
- f(data.value);
195
- return data;
196
- };
197
- /**
198
- * Swaps the roles of error and success values.
199
- * - Err(e) → Ok(e)
200
- * - Ok(a) → Err(a)
201
- * - Both(e, a) → Both(a, e)
200
+ * Returns the second value, or a default if the These has no second value.
202
201
  *
203
202
  * @example
204
203
  * ```ts
205
- * These.swap(These.err("err")); // Ok("err")
206
- * These.swap(These.ok(5)); // Err(5)
207
- * These.swap(These.both("warn", 5)); // Both(5, "warn")
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"
208
207
  * ```
209
208
  */
210
- These.swap = (data) => {
211
- if (These.isErr(data))
212
- return These.ok(data.error);
213
- if (These.isOk(data))
214
- return These.err(data.value);
215
- return These.both(data.value, data.error);
216
- };
209
+ These.getSecondOrElse = (defaultValue) => (data) => These.hasSecond(data) ? data.second : defaultValue;
217
210
  /**
218
- * Converts a These to an Option.
219
- * Ok and Both produce Some; Err produces None.
211
+ * Executes a side effect on the first value without changing the These.
212
+ * Useful for logging or debugging.
220
213
  *
221
214
  * @example
222
215
  * ```ts
223
- * These.toOption(These.ok(42)); // Some(42)
224
- * These.toOption(These.both("warn", 42)); // Some(42)
225
- * These.toOption(These.err("err")); // None
216
+ * pipe(These.first(5), These.tap(console.log)); // logs 5, returns First(5)
226
217
  * ```
227
218
  */
228
- These.toOption = (data) => These.hasValue(data) ? { kind: "Some", value: data.value } : { kind: "None" };
219
+ These.tap = (f) => (data) => {
220
+ if (These.hasFirst(data))
221
+ f(data.first);
222
+ return data;
223
+ };
229
224
  /**
230
- * Converts a These to a Result, discarding any warning from Both.
231
- * Ok and Both produce Ok; Err produces Err.
225
+ * Swaps the roles of first and second values.
226
+ * - First(a) → Second(a)
227
+ * - Second(b) → First(b)
228
+ * - Both(a, b) → Both(b, a)
232
229
  *
233
230
  * @example
234
231
  * ```ts
235
- * These.toResult(These.ok(42)); // Ok(42)
236
- * These.toResult(These.both("warn", 42)); // Ok(42)
237
- * These.toResult(These.err("err")); // Err("err")
232
+ * These.swap(These.first(5)); // Second(5)
233
+ * These.swap(These.second("warn")); // First("warn")
234
+ * These.swap(These.both(5, "warn")); // Both("warn", 5)
238
235
  * ```
239
236
  */
240
- These.toResult = (data) => {
241
- if (These.hasValue(data))
242
- return Result_js_1.Result.ok(data.value);
243
- return data;
237
+ These.swap = (data) => {
238
+ if (These.isSecond(data))
239
+ return These.first(data.second);
240
+ if (These.isFirst(data))
241
+ return These.second(data.first);
242
+ return These.both(data.second, data.first);
244
243
  };
245
244
  })(These || (exports.These = These = {}));
@@ -9,56 +9,55 @@ var Validation;
9
9
  *
10
10
  * @example
11
11
  * ```ts
12
- * Validation.of(42); // Valid(42)
12
+ * Validation.valid(42); // Valid(42)
13
13
  * ```
14
14
  */
15
- Validation.of = (value) => ({
15
+ Validation.valid = (value) => ({
16
16
  kind: "Valid",
17
17
  value,
18
18
  });
19
19
  /**
20
- * Creates a valid Validation with the given value.
21
- */
22
- Validation.toValid = (value) => ({ kind: "Valid", value });
23
- /**
24
- * Type guard that checks if a Validation is valid.
20
+ * Creates an invalid Validation from a single error.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * Validation.invalid("Invalid input");
25
+ * ```
25
26
  */
26
- Validation.isValid = (data) => data.kind === "Valid";
27
+ Validation.invalid = (error) => ({
28
+ kind: "Invalid",
29
+ errors: [error],
30
+ });
27
31
  /**
28
- * Creates an invalid Validation with the given errors.
32
+ * Creates an invalid Validation from multiple errors.
29
33
  *
30
34
  * @example
31
35
  * ```ts
32
- * Validation.toInvalid(["Email is invalid", "Password too short"]);
36
+ * Validation.invalidAll(["Invalid input"]);
33
37
  * ```
34
38
  */
35
- Validation.toInvalid = (errors) => ({
39
+ Validation.invalidAll = (errors) => ({
36
40
  kind: "Invalid",
37
41
  errors,
38
42
  });
39
43
  /**
40
- * Type guard that checks if a Validation is invalid.
44
+ * Type guard that checks if a Validation is valid.
41
45
  */
42
- Validation.isInvalid = (data) => data.kind === "Invalid";
46
+ Validation.isValid = (data) => data.kind === "Valid";
43
47
  /**
44
- * Creates an invalid Validation from a single error.
45
- *
46
- * @example
47
- * ```ts
48
- * Validation.fail("Invalid input");
49
- * ```
48
+ * Type guard that checks if a Validation is invalid.
50
49
  */
51
- Validation.fail = (error) => Validation.toInvalid([error]);
50
+ Validation.isInvalid = (data) => data.kind === "Invalid";
52
51
  /**
53
52
  * Transforms the success value inside a Validation.
54
53
  *
55
54
  * @example
56
55
  * ```ts
57
- * pipe(Validation.of(5), Validation.map(n => n * 2)); // Valid(10)
58
- * pipe(Validation.fail("oops"), Validation.map(n => n * 2)); // Invalid(["oops"])
56
+ * pipe(Validation.valid(5), Validation.map(n => n * 2)); // Valid(10)
57
+ * pipe(Validation.invalid("oops"), Validation.map(n => n * 2)); // Invalid(["oops"])
59
58
  * ```
60
59
  */
61
- Validation.map = (f) => (data) => Validation.isValid(data) ? Validation.of(f(data.value)) : data;
60
+ Validation.map = (f) => (data) => Validation.isValid(data) ? Validation.valid(f(data.value)) : data;
62
61
  /**
63
62
  * Chains Validation computations. If the first is Valid, passes the value to f.
64
63
  * If the first is Invalid, propagates the errors.
@@ -68,10 +67,10 @@ var Validation;
68
67
  * @example
69
68
  * ```ts
70
69
  * const validatePositive = (n: number): Validation<string, number> =>
71
- * n > 0 ? Validation.of(n) : Validation.fail("Must be positive");
70
+ * n > 0 ? Validation.valid(n) : Validation.invalid("Must be positive");
72
71
  *
73
- * pipe(Validation.of(5), Validation.chain(validatePositive)); // Valid(5)
74
- * pipe(Validation.of(-1), Validation.chain(validatePositive)); // Invalid(["Must be positive"])
72
+ * pipe(Validation.valid(5), Validation.chain(validatePositive)); // Valid(5)
73
+ * pipe(Validation.valid(-1), Validation.chain(validatePositive)); // Invalid(["Must be positive"])
75
74
  * ```
76
75
  */
77
76
  Validation.chain = (f) => (data) => Validation.isValid(data) ? f(data.value) : data;
@@ -83,26 +82,26 @@ var Validation;
83
82
  * ```ts
84
83
  * const add = (a: number) => (b: number) => a + b;
85
84
  * pipe(
86
- * Validation.of(add),
87
- * Validation.ap(Validation.of(5)),
88
- * Validation.ap(Validation.of(3))
85
+ * Validation.valid(add),
86
+ * Validation.ap(Validation.valid(5)),
87
+ * Validation.ap(Validation.valid(3))
89
88
  * ); // Valid(8)
90
89
  *
91
90
  * pipe(
92
- * Validation.of(add),
93
- * Validation.ap(Validation.fail<string, number>("bad a")),
94
- * Validation.ap(Validation.fail<string, number>("bad b"))
91
+ * Validation.valid(add),
92
+ * Validation.ap(Validation.invalid<string, number>("bad a")),
93
+ * Validation.ap(Validation.invalid<string, number>("bad b"))
95
94
  * ); // Invalid(["bad a", "bad b"])
96
95
  * ```
97
96
  */
98
97
  Validation.ap = (arg) => (data) => {
99
98
  if (Validation.isValid(data) && Validation.isValid(arg))
100
- return Validation.of(data.value(arg.value));
99
+ return Validation.valid(data.value(arg.value));
101
100
  const errors = [
102
101
  ...(Validation.isInvalid(data) ? data.errors : []),
103
102
  ...(Validation.isInvalid(arg) ? arg.errors : []),
104
103
  ];
105
- return (0, NonEmptyList_js_1.isNonEmptyList)(errors) ? Validation.toInvalid(errors) : Validation.of(data);
104
+ return (0, NonEmptyList_js_1.isNonEmptyList)(errors) ? Validation.invalidAll(errors) : Validation.valid(data);
106
105
  };
107
106
  /**
108
107
  * Extracts the value from a Validation by providing handlers for both cases.
@@ -110,7 +109,7 @@ var Validation;
110
109
  * @example
111
110
  * ```ts
112
111
  * pipe(
113
- * Validation.of(42),
112
+ * Validation.valid(42),
114
113
  * Validation.fold(
115
114
  * errors => `Errors: ${errors.join(", ")}`,
116
115
  * value => `Value: ${value}`
@@ -139,8 +138,8 @@ var Validation;
139
138
  *
140
139
  * @example
141
140
  * ```ts
142
- * pipe(Validation.of(5), Validation.getOrElse(0)); // 5
143
- * pipe(Validation.fail("oops"), Validation.getOrElse(0)); // 0
141
+ * pipe(Validation.valid(5), Validation.getOrElse(0)); // 5
142
+ * pipe(Validation.invalid("oops"), Validation.getOrElse(0)); // 0
144
143
  * ```
145
144
  */
146
145
  Validation.getOrElse = (defaultValue) => (data) => Validation.isValid(data) ? data.value : defaultValue;
@@ -150,7 +149,7 @@ var Validation;
150
149
  * @example
151
150
  * ```ts
152
151
  * pipe(
153
- * Validation.of(5),
152
+ * Validation.valid(5),
154
153
  * Validation.tap(n => console.log("Value:", n)),
155
154
  * Validation.map(n => n * 2)
156
155
  * );
@@ -180,13 +179,13 @@ var Validation;
180
179
  * @example
181
180
  * ```ts
182
181
  * Validation.combine(
183
- * Validation.fail("Error 1"),
184
- * Validation.fail("Error 2")
182
+ * Validation.invalid("Error 1"),
183
+ * Validation.invalid("Error 2")
185
184
  * ); // Invalid(["Error 1", "Error 2"])
186
185
  *
187
186
  * Validation.combine(
188
- * Validation.of("a"),
189
- * Validation.of("b")
187
+ * Validation.valid("a"),
188
+ * Validation.valid("b")
190
189
  * ); // Valid("b")
191
190
  * ```
192
191
  */
@@ -198,7 +197,7 @@ var Validation;
198
197
  ...(Validation.isInvalid(first) ? first.errors : []),
199
198
  ...(Validation.isInvalid(second) ? second.errors : []),
200
199
  ];
201
- return (0, NonEmptyList_js_1.isNonEmptyList)(errors) ? Validation.toInvalid(errors) : second;
200
+ return (0, NonEmptyList_js_1.isNonEmptyList)(errors) ? Validation.invalidAll(errors) : second;
202
201
  };
203
202
  /**
204
203
  * Combines multiple Validation instances, accumulating all errors.
@@ -6,13 +6,13 @@
6
6
  * ```ts
7
7
  * // Original data-last (for pipe)
8
8
  * pipe(
9
- * Option.of(5),
9
+ * Option.some(5),
10
10
  * Option.map(n => n * 2)
11
11
  * ); // Some(10)
12
12
  *
13
13
  * // Flipped to data-first
14
14
  * const mapFirst = flip(Option.map);
15
- * mapFirst(Option.of(5))(n => n * 2); // Some(10)
15
+ * mapFirst(Option.some(5))(n => n * 2); // Some(10)
16
16
  * ```
17
17
  *
18
18
  * @see {@link uncurry} for converting curried functions to multi-argument functions
@@ -4,7 +4,7 @@
4
4
  * @example
5
5
  * ```ts
6
6
  * identity(42); // 42
7
- * pipe(Option.of(5), Option.fold(() => 0, identity)); // 5
7
+ * pipe(Option.some(5), Option.fold(() => 0, identity)); // 5
8
8
  * ```
9
9
  */
10
10
  export declare const identity: <A>(a: A) => A;
@@ -17,7 +17,7 @@
17
17
  *
18
18
  * // With library functions
19
19
  * const greeting = pipe(
20
- * Option.of("Alice"),
20
+ * Option.some("Alice"),
21
21
  * Option.map(name => name.toUpperCase()),
22
22
  * Option.map(name => `Hello, ${name}!`),
23
23
  * Option.getOrElse("Hello!")
@@ -6,7 +6,7 @@
6
6
  * ```ts
7
7
  * // Debugging a pipeline
8
8
  * pipe(
9
- * Option.of(5),
9
+ * Option.some(5),
10
10
  * tap(x => console.log("Before map:", x)),
11
11
  * Option.map(n => n * 2),
12
12
  * tap(x => console.log("After map:", x)),
@@ -11,15 +11,15 @@
11
11
  * uncurry(nested)(); // 42
12
12
  *
13
13
  * // Original curried function
14
- * Option.map(n => n * 2)(Option.of(5)); // Some(10)
14
+ * Option.map(n => n * 2)(Option.some(5)); // Some(10)
15
15
  *
16
16
  * // Uncurried - all arguments at once
17
17
  * const mapUncurried = uncurry(Option.map);
18
- * mapUncurried(n => n * 2, Option.of(5)); // Some(10)
18
+ * mapUncurried(n => n * 2, Option.some(5)); // Some(10)
19
19
  *
20
20
  * // Combined with flip for data-first uncurried
21
21
  * const mapDataFirst = uncurry(flip(Option.map));
22
- * mapDataFirst(Option.of(5), n => n * 2); // Some(10)
22
+ * mapDataFirst(Option.some(5), n => n * 2); // Some(10)
23
23
  * ```
24
24
  *
25
25
  * @see {@link flip} for reversing curried argument order
@@ -227,7 +227,7 @@ export declare namespace Arr {
227
227
  * ```ts
228
228
  * const parseNum = (s: string): Option<number> => {
229
229
  * const n = Number(s);
230
- * return isNaN(n) ? Option.none() : Option.of(n);
230
+ * return isNaN(n) ? Option.none() : Option.some(n);
231
231
  * };
232
232
  *
233
233
  * pipe(["1", "2", "3"], Arr.traverse(parseNum)); // Some([1, 2, 3])
@@ -255,7 +255,7 @@ export declare namespace Arr {
255
255
  * ```ts
256
256
  * pipe(
257
257
  * [1, 2, 3],
258
- * Arr.traverseTask(n => Task.of(n * 2))
258
+ * Arr.traverseTask(n => Task.resolve(n * 2))
259
259
  * )(); // Promise<[2, 4, 6]>
260
260
  * ```
261
261
  */
@@ -266,8 +266,8 @@ export declare namespace Arr {
266
266
  *
267
267
  * @example
268
268
  * ```ts
269
- * Arr.sequence([Option.of(1), Option.of(2)]); // Some([1, 2])
270
- * Arr.sequence([Option.of(1), Option.none()]); // None
269
+ * Arr.sequence([Option.some(1), Option.some(2)]); // Some([1, 2])
270
+ * Arr.sequence([Option.some(1), Option.none()]); // None
271
271
  * ```
272
272
  */
273
273
  const sequence: <A>(data: readonly Option<A>[]) => Option<readonly A[]>;
@@ -11,4 +11,10 @@ export type WithError<T> = {
11
11
  export type WithErrors<T> = {
12
12
  readonly errors: NonEmptyList<T>;
13
13
  };
14
+ export type WithFirst<T> = {
15
+ readonly first: T;
16
+ };
17
+ export type WithSecond<T> = {
18
+ readonly second: T;
19
+ };
14
20
  //# sourceMappingURL=InternalTypes.d.ts.map