@nlozgachev/pipekit 0.3.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.
@@ -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 a success value (no error).
4
+ * Creates a These holding only a first value.
6
5
  *
7
6
  * @example
8
7
  * ```ts
9
- * These.ok(42);
8
+ * These.first(42); // { kind: "First", first: 42 }
10
9
  * ```
11
10
  */
12
- These.ok = (value) => Result.ok(value);
11
+ These.first = (value) => ({ kind: "First", first: value });
13
12
  /**
14
- * Creates a These holding only an error/warning (no success value).
13
+ * Creates a These holding only a second value.
15
14
  *
16
15
  * @example
17
16
  * ```ts
18
- * These.err("Something went wrong");
17
+ * These.second("warning"); // { kind: "Second", second: "warning" }
19
18
  * ```
20
19
  */
21
- These.err = (error) => Result.err(error);
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 = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nlozgachev/pipekit",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Simple functional programming toolkit for TypeScript",
5
5
  "keywords": [
6
6
  "functional",
@@ -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 a success value (no error).
7
+ * Creates a These holding only a first value.
9
8
  *
10
9
  * @example
11
10
  * ```ts
12
- * These.ok(42);
11
+ * These.first(42); // { kind: "First", first: 42 }
13
12
  * ```
14
13
  */
15
- These.ok = (value) => Result_js_1.Result.ok(value);
14
+ These.first = (value) => ({ kind: "First", first: value });
16
15
  /**
17
- * Creates a These holding only an error/warning (no success value).
16
+ * Creates a These holding only a second value.
18
17
  *
19
18
  * @example
20
19
  * ```ts
21
- * These.err("Something went wrong");
20
+ * These.second("warning"); // { kind: "Second", second: "warning" }
22
21
  * ```
23
22
  */
24
- These.err = (error) => Result_js_1.Result.err(error);
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 = {}));
@@ -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
@@ -1 +1 @@
1
- {"version":3,"file":"InternalTypes.d.ts","sourceRoot":"","sources":["../../../src/src/Core/InternalTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,MAAM,IAAI;IAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC;AAE9D,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAEjD,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAEjD,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;IAAE,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC"}
1
+ {"version":3,"file":"InternalTypes.d.ts","sourceRoot":"","sources":["../../../src/src/Core/InternalTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,MAAM,IAAI;IAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC;AAE9D,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAEjD,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAEjD,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;IAAE,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC;AAEjE,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAEjD,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;IAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;CAAE,CAAC"}
@@ -1,124 +1,140 @@
1
- import { Err, Ok, Result } from "./Result.js";
2
- import { WithError, WithKind, WithValue } from "./InternalTypes.js";
1
+ import { WithFirst, WithKind, WithSecond } from "./InternalTypes.js";
3
2
  /**
4
- * These<E, A> is an inclusive-OR type: it holds an error value (E), a success
5
- * value (A), or both simultaneously. It reuses Ok<A> and Err<E> from Result,
6
- * adding a third Both<E, A> variant for partial success with a warning/error.
3
+ * These<A, B> is an inclusive-OR type: it holds a first value (A), a second
4
+ * value (B), or both simultaneously. Neither side carries a success/failure
5
+ * connotation it is a neutral pair where any combination is valid.
7
6
  *
8
- * - Err(e) — only an error/warning (no success value)
9
- * - Ok(a) — only a success value (no error)
10
- * - Both(e, a) a warning together with a success value
7
+ * - First(a) — only a first value
8
+ * - Second(b) — only a second value
9
+ * - Both(a, b) first and second values simultaneously
10
+ *
11
+ * A common use: lenient parsers or processors that carry a diagnostic note
12
+ * alongside a result, without losing either piece of information.
11
13
  *
12
14
  * @example
13
15
  * ```ts
14
- * const parse = (s: string): These<string, number> => {
15
- * const n = parseFloat(s.trim());
16
- * if (isNaN(n)) return These.err("Not a number");
17
- * if (s !== s.trim()) return These.both("Leading/trailing whitespace trimmed", n);
18
- * return These.ok(n);
16
+ * const parse = (s: string): These<number, string> => {
17
+ * const trimmed = s.trim();
18
+ * const n = parseFloat(trimmed);
19
+ * if (isNaN(n)) return These.second("Not a number");
20
+ * if (s !== trimmed) return These.both(n, "Leading/trailing whitespace trimmed");
21
+ * return These.first(n);
19
22
  * };
20
23
  * ```
21
24
  */
22
- export type These<E, A> = Err<E> | Ok<A> | Both<E, A>;
23
- export type Both<E, A> = WithKind<"Both"> & WithError<E> & WithValue<A>;
25
+ export type These<A, B> = TheseFirst<A> | TheseSecond<B> | TheseBoth<A, B>;
26
+ export type TheseFirst<T> = WithKind<"First"> & WithFirst<T>;
27
+ export type TheseSecond<T> = WithKind<"Second"> & WithSecond<T>;
28
+ export type TheseBoth<First, Second> = WithKind<"Both"> & WithFirst<First> & WithSecond<Second>;
24
29
  export declare namespace These {
25
30
  /**
26
- * Creates a These holding only a success value (no error).
31
+ * Creates a These holding only a first value.
27
32
  *
28
33
  * @example
29
34
  * ```ts
30
- * These.ok(42);
35
+ * These.first(42); // { kind: "First", first: 42 }
31
36
  * ```
32
37
  */
33
- const ok: <A>(value: A) => Ok<A>;
38
+ const first: <A>(value: A) => TheseFirst<A>;
34
39
  /**
35
- * Creates a These holding only an error/warning (no success value).
40
+ * Creates a These holding only a second value.
36
41
  *
37
42
  * @example
38
43
  * ```ts
39
- * These.err("Something went wrong");
44
+ * These.second("warning"); // { kind: "Second", second: "warning" }
40
45
  * ```
41
46
  */
42
- const err: <E>(error: E) => Err<E>;
47
+ const second: <B>(value: B) => TheseSecond<B>;
43
48
  /**
44
- * Creates a These holding both an error/warning and a success value.
49
+ * Creates a These holding both a first and a second value simultaneously.
45
50
  *
46
51
  * @example
47
52
  * ```ts
48
- * These.both("Deprecated API used", result);
53
+ * These.both(42, "Deprecated API used"); // { kind: "Both", first: 42, second: "Deprecated API used" }
49
54
  * ```
50
55
  */
51
- const both: <E, A>(error: E, value: A) => Both<E, A>;
56
+ const both: <A, B>(first: A, second: B) => TheseBoth<A, B>;
52
57
  /**
53
- * Type guard — checks if a These holds only an error/warning.
58
+ * Type guard — checks if a These holds only a first value.
54
59
  */
55
- const isErr: <E, A>(data: These<E, A>) => data is Err<E>;
60
+ const isFirst: <A, B>(data: These<A, B>) => data is TheseFirst<A>;
56
61
  /**
57
- * Type guard — checks if a These holds only a success value.
62
+ * Type guard — checks if a These holds only a second value.
58
63
  */
59
- const isOk: <E, A>(data: These<E, A>) => data is Ok<A>;
64
+ const isSecond: <A, B>(data: These<A, B>) => data is TheseSecond<B>;
60
65
  /**
61
- * Type guard — checks if a These holds both an error/warning and a success value.
66
+ * Type guard — checks if a These holds both values simultaneously.
62
67
  */
63
- const isBoth: <E, A>(data: These<E, A>) => data is Both<E, A>;
68
+ const isBoth: <A, B>(data: These<A, B>) => data is TheseBoth<A, B>;
64
69
  /**
65
- * Returns true if the These contains a success value (Ok or Both).
70
+ * Returns true if the These contains a first value (First or Both).
66
71
  */
67
- const hasValue: <E, A>(data: These<E, A>) => data is Ok<A> | Both<E, A>;
72
+ const hasFirst: <A, B>(data: These<A, B>) => data is TheseFirst<A> | TheseBoth<A, B>;
68
73
  /**
69
- * Returns true if the These contains an error/warning (Err or Both).
74
+ * Returns true if the These contains a second value (Second or Both).
70
75
  */
71
- const hasError: <E, A>(data: These<E, A>) => data is Err<E> | Both<E, A>;
76
+ const hasSecond: <A, B>(data: These<A, B>) => data is TheseSecond<B> | TheseBoth<A, B>;
72
77
  /**
73
- * Transforms the success value, leaving the error unchanged.
78
+ * Transforms the first value, leaving the second unchanged.
74
79
  *
75
80
  * @example
76
81
  * ```ts
77
- * pipe(These.ok(5), These.map(n => n * 2)); // Ok(10)
78
- * pipe(These.both("warn", 5), These.map(n => n * 2)); // Both("warn", 10)
79
- * pipe(These.err("err"), These.map(n => n * 2)); // Err("err")
82
+ * pipe(These.first(5), These.mapFirst(n => n * 2)); // First(10)
83
+ * pipe(These.both(5, "warn"), These.mapFirst(n => n * 2)); // Both(10, "warn")
84
+ * pipe(These.second("warn"), These.mapFirst(n => n * 2)); // Second("warn")
80
85
  * ```
81
86
  */
82
- const map: <A, B>(f: (a: A) => B) => <E>(data: These<E, A>) => These<E, B>;
87
+ const mapFirst: <A, C>(f: (a: A) => C) => <B>(data: These<A, B>) => These<C, B>;
83
88
  /**
84
- * Transforms the error/warning value, leaving the success value unchanged.
89
+ * Transforms the second value, leaving the first unchanged.
85
90
  *
86
91
  * @example
87
92
  * ```ts
88
- * pipe(These.err("err"), These.mapErr(e => e.toUpperCase())); // Err("ERR")
89
- * pipe(These.both("warn", 5), These.mapErr(e => e.toUpperCase())); // Both("WARN", 5)
93
+ * pipe(These.second("warn"), These.mapSecond(e => e.toUpperCase())); // Second("WARN")
94
+ * pipe(These.both(5, "warn"), These.mapSecond(e => e.toUpperCase())); // Both(5, "WARN")
90
95
  * ```
91
96
  */
92
- const mapErr: <E, F>(f: (e: E) => F) => <A>(data: These<E, A>) => These<F, A>;
97
+ const mapSecond: <B, D>(f: (b: B) => D) => <A>(data: These<A, B>) => These<A, D>;
93
98
  /**
94
- * Transforms both the error and success values independently.
99
+ * Transforms both the first and second values independently.
95
100
  *
96
101
  * @example
97
102
  * ```ts
98
103
  * pipe(
99
- * These.both("warn", 5),
100
- * These.bimap(e => e.toUpperCase(), n => n * 2)
101
- * ); // Both("WARN", 10)
104
+ * These.both(5, "warn"),
105
+ * These.mapBoth(n => n * 2, e => e.toUpperCase())
106
+ * ); // Both(10, "WARN")
107
+ * ```
108
+ */
109
+ const mapBoth: <A, C, B, D>(onFirst: (a: A) => C, onSecond: (b: B) => D) => (data: These<A, B>) => These<C, D>;
110
+ /**
111
+ * Chains These computations by passing the first value to f.
112
+ * Second propagates unchanged; First and Both apply f to the first value.
113
+ *
114
+ * @example
115
+ * ```ts
116
+ * const double = (n: number): These<number, string> => These.first(n * 2);
117
+ *
118
+ * pipe(These.first(5), These.chainFirst(double)); // First(10)
119
+ * pipe(These.both(5, "warn"), These.chainFirst(double)); // First(10)
120
+ * pipe(These.second("warn"), These.chainFirst(double)); // Second("warn")
102
121
  * ```
103
122
  */
104
- const bimap: <E, F, A, B>(onErr: (e: E) => F, onOk: (a: A) => B) => (data: These<E, A>) => These<F, B>;
123
+ const chainFirst: <A, B, C>(f: (a: A) => These<C, B>) => (data: These<A, B>) => These<C, B>;
105
124
  /**
106
- * Chains These computations by passing the success value to f.
107
- * - Err propagates unchanged.
108
- * - Ok(a) applies f(a) directly.
109
- * - Both(e, a): applies f(a); if the result is Ok(b), returns Both(e, b)
110
- * to preserve the warning. Otherwise returns f(a) as-is.
125
+ * Chains These computations by passing the second value to f.
126
+ * First propagates unchanged; Second and Both apply f to the second value.
111
127
  *
112
128
  * @example
113
129
  * ```ts
114
- * const double = (n: number): These<string, number> => These.ok(n * 2);
130
+ * const shout = (s: string): These<number, string> => These.second(s.toUpperCase());
115
131
  *
116
- * pipe(These.ok(5), These.chain(double)); // Ok(10)
117
- * pipe(These.both("warn", 5), These.chain(double)); // Both("warn", 10)
118
- * pipe(These.err("err"), These.chain(double)); // Err("err")
132
+ * pipe(These.second("warn"), These.chainSecond(shout)); // Second("WARN")
133
+ * pipe(These.both(5, "warn"), These.chainSecond(shout)); // Second("WARN")
134
+ * pipe(These.first(5), These.chainSecond(shout)); // First(5)
119
135
  * ```
120
136
  */
121
- const chain: <E, A, B>(f: (a: A) => These<E, B>) => (data: These<E, A>) => These<E, B>;
137
+ const chainSecond: <A, B, D>(f: (b: B) => These<A, D>) => (data: These<A, B>) => These<A, D>;
122
138
  /**
123
139
  * Extracts a value from a These by providing handlers for all three cases.
124
140
  *
@@ -127,14 +143,14 @@ export declare namespace These {
127
143
  * pipe(
128
144
  * these,
129
145
  * These.fold(
130
- * e => `Error: ${e}`,
131
- * a => `Value: ${a}`,
132
- * (e, a) => `Both: ${e} / ${a}`
146
+ * a => `First: ${a}`,
147
+ * b => `Second: ${b}`,
148
+ * (a, b) => `Both: ${a} / ${b}`
133
149
  * )
134
150
  * );
135
151
  * ```
136
152
  */
137
- const fold: <E, A, B>(onErr: (e: E) => B, onOk: (a: A) => B, onBoth: (e: E, a: A) => B) => (data: These<E, A>) => B;
153
+ const fold: <A, B, C>(onFirst: (a: A) => C, onSecond: (b: B) => C, onBoth: (a: A, b: B) => C) => (data: These<A, B>) => C;
138
154
  /**
139
155
  * Pattern matches on a These, returning the result of the matching case.
140
156
  *
@@ -143,71 +159,63 @@ export declare namespace These {
143
159
  * pipe(
144
160
  * these,
145
161
  * These.match({
146
- * err: e => `Error: ${e}`,
147
- * ok: a => `Value: ${a}`,
148
- * both: (e, a) => `Both: ${e} / ${a}`
162
+ * first: a => `First: ${a}`,
163
+ * second: b => `Second: ${b}`,
164
+ * both: (a, b) => `Both: ${a} / ${b}`
149
165
  * })
150
166
  * );
151
167
  * ```
152
168
  */
153
- const match: <E, A, B>(cases: {
154
- err: (e: E) => B;
155
- ok: (a: A) => B;
156
- both: (e: E, a: A) => B;
157
- }) => (data: These<E, A>) => B;
169
+ const match: <A, B, C>(cases: {
170
+ first: (a: A) => C;
171
+ second: (b: B) => C;
172
+ both: (a: A, b: B) => C;
173
+ }) => (data: These<A, B>) => C;
158
174
  /**
159
- * Returns the success value, or a default if the These has no success value.
175
+ * Returns the first value, or a default if the These has no first value.
160
176
  *
161
177
  * @example
162
178
  * ```ts
163
- * pipe(These.ok(5), These.getOrElse(0)); // 5
164
- * pipe(These.both("warn", 5), These.getOrElse(0)); // 5
165
- * pipe(These.err("err"), These.getOrElse(0)); // 0
179
+ * pipe(These.first(5), These.getFirstOrElse(0)); // 5
180
+ * pipe(These.both(5, "warn"), These.getFirstOrElse(0)); // 5
181
+ * pipe(These.second("warn"), These.getFirstOrElse(0)); // 0
166
182
  * ```
167
183
  */
168
- const getOrElse: <A>(defaultValue: A) => <E>(data: These<E, A>) => A;
169
- /**
170
- * Executes a side effect on the success value without changing the These.
171
- * Useful for logging or debugging.
172
- */
173
- const tap: <A>(f: (a: A) => void) => <E>(data: These<E, A>) => These<E, A>;
184
+ const getFirstOrElse: <A>(defaultValue: A) => <B>(data: These<A, B>) => A;
174
185
  /**
175
- * Swaps the roles of error and success values.
176
- * - Err(e) → Ok(e)
177
- * - Ok(a) → Err(a)
178
- * - Both(e, a) → Both(a, e)
186
+ * Returns the second value, or a default if the These has no second value.
179
187
  *
180
188
  * @example
181
189
  * ```ts
182
- * These.swap(These.err("err")); // Ok("err")
183
- * These.swap(These.ok(5)); // Err(5)
184
- * These.swap(These.both("warn", 5)); // Both(5, "warn")
190
+ * pipe(These.second("warn"), These.getSecondOrElse("none")); // "warn"
191
+ * pipe(These.both(5, "warn"), These.getSecondOrElse("none")); // "warn"
192
+ * pipe(These.first(5), These.getSecondOrElse("none")); // "none"
185
193
  * ```
186
194
  */
187
- const swap: <E, A>(data: These<E, A>) => These<A, E>;
195
+ const getSecondOrElse: <B>(defaultValue: B) => <A>(data: These<A, B>) => B;
188
196
  /**
189
- * Converts a These to an Option.
190
- * Ok and Both produce Some; Err produces None.
197
+ * Executes a side effect on the first value without changing the These.
198
+ * Useful for logging or debugging.
191
199
  *
192
200
  * @example
193
201
  * ```ts
194
- * These.toOption(These.ok(42)); // Some(42)
195
- * These.toOption(These.both("warn", 42)); // Some(42)
196
- * These.toOption(These.err("err")); // None
202
+ * pipe(These.first(5), These.tap(console.log)); // logs 5, returns First(5)
197
203
  * ```
198
204
  */
199
- const toOption: <E, A>(data: These<E, A>) => import("./Option.ts").Option<A>;
205
+ const tap: <A>(f: (a: A) => void) => <B>(data: These<A, B>) => These<A, B>;
200
206
  /**
201
- * Converts a These to a Result, discarding any warning from Both.
202
- * Ok and Both produce Ok; Err produces Err.
207
+ * Swaps the roles of first and second values.
208
+ * - First(a) → Second(a)
209
+ * - Second(b) → First(b)
210
+ * - Both(a, b) → Both(b, a)
203
211
  *
204
212
  * @example
205
213
  * ```ts
206
- * These.toResult(These.ok(42)); // Ok(42)
207
- * These.toResult(These.both("warn", 42)); // Ok(42)
208
- * These.toResult(These.err("err")); // Err("err")
214
+ * These.swap(These.first(5)); // Second(5)
215
+ * These.swap(These.second("warn")); // First("warn")
216
+ * These.swap(These.both(5, "warn")); // Both("warn", 5)
209
217
  * ```
210
218
  */
211
- const toResult: <E, A>(data: These<E, A>) => Result<E, A>;
219
+ const swap: <A, B>(data: These<A, B>) => These<B, A>;
212
220
  }
213
221
  //# sourceMappingURL=These.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"These.d.ts","sourceRoot":"","sources":["../../../src/src/Core/These.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO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