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