@nlozgachev/pipekit 0.1.6 → 0.1.8

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.
@@ -0,0 +1,28 @@
1
+ export var Brand;
2
+ (function (Brand) {
3
+ /**
4
+ * Creates a branding constructor for brand K over type T.
5
+ * The resulting function performs an unchecked cast — only use when the raw
6
+ * value is known to satisfy the brand's invariants.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * type PositiveNumber = Brand<"PositiveNumber", number>;
11
+ * const toPositiveNumber = Brand.make<"PositiveNumber", number>();
12
+ *
13
+ * const n: PositiveNumber = toPositiveNumber(42);
14
+ * ```
15
+ */
16
+ Brand.make = () => (value) => value;
17
+ /**
18
+ * Strips the brand and returns the underlying value.
19
+ * Since Brand<K, T> extends T this is rarely needed, but can improve readability.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * const userId: UserId = toUserId("user-123");
24
+ * const raw: string = Brand.unwrap(userId); // "user-123"
25
+ * ```
26
+ */
27
+ Brand.unwrap = (branded) => branded;
28
+ })(Brand || (Brand = {}));
@@ -1 +1,2 @@
1
+ export * from "./Brand.js";
1
2
  export * from "./NonEmptyList.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nlozgachev/pipekit",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Simple functional programming toolkit for TypeScript",
5
5
  "keywords": [
6
6
  "functional",
@@ -9,6 +9,7 @@
9
9
  "composition",
10
10
  "pipe"
11
11
  ],
12
+ "homepage": "https://pipekit.lozgachev.dev",
12
13
  "repository": {
13
14
  "type": "git",
14
15
  "url": "https://github.com/nlozgachev/pipekit"
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TaskOption = void 0;
4
+ const Option_js_1 = require("./Option.js");
5
+ const Task_js_1 = require("./Task.js");
6
+ var TaskOption;
7
+ (function (TaskOption) {
8
+ /**
9
+ * Wraps a value in a Some inside a Task.
10
+ */
11
+ TaskOption.of = (value) => Task_js_1.Task.of(Option_js_1.Option.of(value));
12
+ /**
13
+ * Creates a TaskOption that resolves to None.
14
+ */
15
+ TaskOption.none = () => Task_js_1.Task.of(Option_js_1.Option.toNone());
16
+ /**
17
+ * Lifts an Option into a TaskOption.
18
+ */
19
+ TaskOption.fromOption = (option) => Task_js_1.Task.of(option);
20
+ /**
21
+ * Lifts a Task into a TaskOption by wrapping its result in Some.
22
+ */
23
+ TaskOption.fromTask = (task) => Task_js_1.Task.map(Option_js_1.Option.of)(task);
24
+ /**
25
+ * Creates a TaskOption from a Promise-returning function.
26
+ * Returns Some if the promise resolves, None if it rejects.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const fetchUser = TaskOption.tryCatch(() =>
31
+ * fetch("/user/1").then(r => r.json())
32
+ * );
33
+ * ```
34
+ */
35
+ TaskOption.tryCatch = (f) => () => f().then(Option_js_1.Option.of).catch(() => Option_js_1.Option.toNone());
36
+ /**
37
+ * Transforms the value inside a TaskOption.
38
+ */
39
+ TaskOption.map = (f) => (data) => Task_js_1.Task.map(Option_js_1.Option.map(f))(data);
40
+ /**
41
+ * Chains TaskOption computations. If the first resolves to Some, passes the
42
+ * value to f. If the first resolves to None, propagates None.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * pipe(
47
+ * findUser("123"),
48
+ * TaskOption.chain(user => findOrg(user.orgId))
49
+ * )();
50
+ * ```
51
+ */
52
+ TaskOption.chain = (f) => (data) => Task_js_1.Task.chain((option) => Option_js_1.Option.isSome(option) ? f(option.value) : Task_js_1.Task.of(Option_js_1.Option.toNone()))(data);
53
+ /**
54
+ * Applies a function wrapped in a TaskOption to a value wrapped in a TaskOption.
55
+ * Both Tasks run in parallel.
56
+ */
57
+ TaskOption.ap = (arg) => (data) => () => Promise.all([data(), arg()]).then(([of_, oa]) => Option_js_1.Option.ap(oa)(of_));
58
+ /**
59
+ * Extracts a value from a TaskOption by providing handlers for both cases.
60
+ */
61
+ TaskOption.fold = (onNone, onSome) => (data) => Task_js_1.Task.map(Option_js_1.Option.fold(onNone, onSome))(data);
62
+ /**
63
+ * Pattern matches on a TaskOption, returning a Task of the result.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * pipe(
68
+ * findUser("123"),
69
+ * TaskOption.match({
70
+ * some: user => `Hello, ${user.name}`,
71
+ * none: () => "User not found"
72
+ * })
73
+ * )();
74
+ * ```
75
+ */
76
+ TaskOption.match = (cases) => (data) => Task_js_1.Task.map(Option_js_1.Option.match(cases))(data);
77
+ /**
78
+ * Returns the value or a default if the TaskOption resolves to None.
79
+ */
80
+ TaskOption.getOrElse = (defaultValue) => (data) => Task_js_1.Task.map(Option_js_1.Option.getOrElse(defaultValue))(data);
81
+ /**
82
+ * Executes a side effect on the value without changing the TaskOption.
83
+ * Useful for logging or debugging.
84
+ */
85
+ TaskOption.tap = (f) => (data) => Task_js_1.Task.map(Option_js_1.Option.tap(f))(data);
86
+ /**
87
+ * Filters the value inside a TaskOption. Returns None if the predicate fails.
88
+ */
89
+ TaskOption.filter = (predicate) => (data) => Task_js_1.Task.map(Option_js_1.Option.filter(predicate))(data);
90
+ /**
91
+ * Converts a TaskOption to a TaskResult, using onNone to produce the error value.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * pipe(
96
+ * findUser("123"),
97
+ * TaskOption.toTaskResult(() => "User not found")
98
+ * );
99
+ * ```
100
+ */
101
+ TaskOption.toTaskResult = (onNone) => (data) => Task_js_1.Task.map(Option_js_1.Option.toResult(onNone))(data);
102
+ })(TaskOption || (exports.TaskOption = TaskOption = {}));
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TaskValidation = void 0;
4
+ const Task_js_1 = require("./Task.js");
5
+ const Validation_js_1 = require("./Validation.js");
6
+ var TaskValidation;
7
+ (function (TaskValidation) {
8
+ /**
9
+ * Wraps a value in a valid TaskValidation.
10
+ */
11
+ TaskValidation.of = (value) => Task_js_1.Task.of(Validation_js_1.Validation.of(value));
12
+ /**
13
+ * Creates a failed TaskValidation with a single error.
14
+ */
15
+ TaskValidation.fail = (error) => Task_js_1.Task.of(Validation_js_1.Validation.fail(error));
16
+ /**
17
+ * Lifts a Validation into a TaskValidation.
18
+ */
19
+ TaskValidation.fromValidation = (validation) => Task_js_1.Task.of(validation);
20
+ /**
21
+ * Creates a TaskValidation from a Promise-returning function.
22
+ * Catches any errors and transforms them using the onError function.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const fetchUser = (id: string): TaskValidation<string, User> =>
27
+ * TaskValidation.tryCatch(
28
+ * () => fetch(`/users/${id}`).then(r => r.json()),
29
+ * e => `Failed to fetch user: ${e}`
30
+ * );
31
+ * ```
32
+ */
33
+ TaskValidation.tryCatch = (f, onError) => () => f()
34
+ .then((Validation_js_1.Validation.of))
35
+ .catch((e) => Validation_js_1.Validation.fail(onError(e)));
36
+ /**
37
+ * Transforms the success value inside a TaskValidation.
38
+ */
39
+ TaskValidation.map = (f) => (data) => Task_js_1.Task.map(Validation_js_1.Validation.map(f))(data);
40
+ /**
41
+ * Chains TaskValidation computations. If the first is Valid, passes the value
42
+ * to f. If the first is Invalid, propagates the errors.
43
+ *
44
+ * Note: chain short-circuits on first error. Use ap to accumulate errors.
45
+ */
46
+ TaskValidation.chain = (f) => (data) => Task_js_1.Task.chain((validation) => Validation_js_1.Validation.isValid(validation)
47
+ ? f(validation.value)
48
+ : Task_js_1.Task.of(Validation_js_1.Validation.toInvalid(validation.errors)))(data);
49
+ /**
50
+ * Applies a function wrapped in a TaskValidation to a value wrapped in a
51
+ * TaskValidation. Both Tasks run in parallel and errors from both sides
52
+ * are accumulated.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * pipe(
57
+ * TaskValidation.of((name: string) => (age: number) => ({ name, age })),
58
+ * TaskValidation.ap(validateName(name)),
59
+ * TaskValidation.ap(validateAge(age))
60
+ * )();
61
+ * ```
62
+ */
63
+ TaskValidation.ap = (arg) => (data) => () => Promise.all([data(), arg()]).then(([vf, va]) => Validation_js_1.Validation.ap(va)(vf));
64
+ /**
65
+ * Extracts a value from a TaskValidation by providing handlers for both cases.
66
+ */
67
+ TaskValidation.fold = (onInvalid, onValid) => (data) => Task_js_1.Task.map(Validation_js_1.Validation.fold(onInvalid, onValid))(data);
68
+ /**
69
+ * Pattern matches on a TaskValidation, returning a Task of the result.
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * pipe(
74
+ * validateForm(input),
75
+ * TaskValidation.match({
76
+ * valid: data => save(data),
77
+ * invalid: errors => showErrors(errors)
78
+ * })
79
+ * )();
80
+ * ```
81
+ */
82
+ TaskValidation.match = (cases) => (data) => Task_js_1.Task.map(Validation_js_1.Validation.match(cases))(data);
83
+ /**
84
+ * Returns the success value or a default value if the TaskValidation is invalid.
85
+ */
86
+ TaskValidation.getOrElse = (defaultValue) => (data) => Task_js_1.Task.map(Validation_js_1.Validation.getOrElse(defaultValue))(data);
87
+ /**
88
+ * Executes a side effect on the success value without changing the TaskValidation.
89
+ * Useful for logging or debugging.
90
+ */
91
+ TaskValidation.tap = (f) => (data) => Task_js_1.Task.map(Validation_js_1.Validation.tap(f))(data);
92
+ /**
93
+ * Recovers from an Invalid state by providing a fallback TaskValidation.
94
+ */
95
+ TaskValidation.recover = (fallback) => (data) => Task_js_1.Task.chain((validation) => Validation_js_1.Validation.isValid(validation) ? Task_js_1.Task.of(validation) : fallback())(data);
96
+ })(TaskValidation || (exports.TaskValidation = TaskValidation = {}));
@@ -0,0 +1,245 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.These = void 0;
4
+ const Result_js_1 = require("./Result.js");
5
+ var These;
6
+ (function (These) {
7
+ /**
8
+ * Creates a These holding only an error/warning (no success value).
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * These.toErr("Something went wrong");
13
+ * ```
14
+ */
15
+ These.toErr = (error) => Result_js_1.Result.toErr(error);
16
+ /**
17
+ * Creates a These holding only a success value (no error).
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * These.toOk(42);
22
+ * ```
23
+ */
24
+ These.toOk = (value) => Result_js_1.Result.toOk(value);
25
+ /**
26
+ * Creates a These holding both an error/warning and a success value.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * These.toBoth("Deprecated API used", result);
31
+ * ```
32
+ */
33
+ These.toBoth = (error, value) => ({
34
+ kind: "Both",
35
+ error,
36
+ value,
37
+ });
38
+ /**
39
+ * Type guard — checks if a These holds only an error/warning.
40
+ */
41
+ These.isErr = (data) => data.kind === "Error";
42
+ /**
43
+ * Type guard — checks if a These holds only a success value.
44
+ */
45
+ These.isOk = (data) => data.kind === "Ok";
46
+ /**
47
+ * Type guard — checks if a These holds both an error/warning and a success value.
48
+ */
49
+ These.isBoth = (data) => data.kind === "Both";
50
+ /**
51
+ * Returns true if the These contains a success value (Ok or Both).
52
+ */
53
+ These.hasValue = (data) => data.kind === "Ok" || data.kind === "Both";
54
+ /**
55
+ * Returns true if the These contains an error/warning (Err or Both).
56
+ */
57
+ These.hasError = (data) => data.kind === "Error" || data.kind === "Both";
58
+ /**
59
+ * Transforms the success value, leaving the error unchanged.
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * pipe(These.toOk(5), These.map(n => n * 2)); // Ok(10)
64
+ * pipe(These.toBoth("warn", 5), These.map(n => n * 2)); // Both("warn", 10)
65
+ * pipe(These.toErr("err"), These.map(n => n * 2)); // Err("err")
66
+ * ```
67
+ */
68
+ These.map = (f) => (data) => {
69
+ if (These.isErr(data))
70
+ return data;
71
+ if (These.isOk(data))
72
+ return These.toOk(f(data.value));
73
+ return These.toBoth(data.error, f(data.value));
74
+ };
75
+ /**
76
+ * Transforms the error/warning value, leaving the success value unchanged.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * pipe(These.toErr("err"), These.mapErr(e => e.toUpperCase())); // Err("ERR")
81
+ * pipe(These.toBoth("warn", 5), These.mapErr(e => e.toUpperCase())); // Both("WARN", 5)
82
+ * ```
83
+ */
84
+ These.mapErr = (f) => (data) => {
85
+ if (These.isOk(data))
86
+ return data;
87
+ if (These.isErr(data))
88
+ return These.toErr(f(data.error));
89
+ return These.toBoth(f(data.error), data.value);
90
+ };
91
+ /**
92
+ * Transforms both the error and success values independently.
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * pipe(
97
+ * These.toBoth("warn", 5),
98
+ * These.bimap(e => e.toUpperCase(), n => n * 2)
99
+ * ); // Both("WARN", 10)
100
+ * ```
101
+ */
102
+ These.bimap = (onErr, onOk) => (data) => {
103
+ if (These.isErr(data))
104
+ return These.toErr(onErr(data.error));
105
+ if (These.isOk(data))
106
+ return These.toOk(onOk(data.value));
107
+ return These.toBoth(onErr(data.error), onOk(data.value));
108
+ };
109
+ /**
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.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * const double = (n: number): These<string, number> => These.toOk(n * 2);
119
+ *
120
+ * pipe(These.toOk(5), These.chain(double)); // Ok(10)
121
+ * pipe(These.toBoth("warn", 5), These.chain(double)); // Both("warn", 10)
122
+ * pipe(These.toErr("err"), These.chain(double)); // Err("err")
123
+ * ```
124
+ */
125
+ These.chain = (f) => (data) => {
126
+ if (These.isErr(data))
127
+ return data;
128
+ if (These.isOk(data))
129
+ return f(data.value);
130
+ const result = f(data.value);
131
+ return These.isOk(result) ? These.toBoth(data.error, result.value) : result;
132
+ };
133
+ /**
134
+ * Extracts a value from a These by providing handlers for all three cases.
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * pipe(
139
+ * these,
140
+ * These.fold(
141
+ * e => `Error: ${e}`,
142
+ * a => `Value: ${a}`,
143
+ * (e, a) => `Both: ${e} / ${a}`
144
+ * )
145
+ * );
146
+ * ```
147
+ */
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);
154
+ };
155
+ /**
156
+ * Pattern matches on a These, returning the result of the matching case.
157
+ *
158
+ * @example
159
+ * ```ts
160
+ * pipe(
161
+ * these,
162
+ * These.match({
163
+ * err: e => `Error: ${e}`,
164
+ * ok: a => `Value: ${a}`,
165
+ * both: (e, a) => `Both: ${e} / ${a}`
166
+ * })
167
+ * );
168
+ * ```
169
+ */
170
+ 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);
176
+ };
177
+ /**
178
+ * Returns the success value, or a default if the These has no success value.
179
+ *
180
+ * @example
181
+ * ```ts
182
+ * pipe(These.toOk(5), These.getOrElse(0)); // 5
183
+ * pipe(These.toBoth("warn", 5), These.getOrElse(0)); // 5
184
+ * pipe(These.toErr("err"), These.getOrElse(0)); // 0
185
+ * ```
186
+ */
187
+ These.getOrElse = (defaultValue) => (data) => These.hasValue(data) ? data.value : defaultValue;
188
+ /**
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)
202
+ *
203
+ * @example
204
+ * ```ts
205
+ * These.swap(These.toErr("err")); // Ok("err")
206
+ * These.swap(These.toOk(5)); // Err(5)
207
+ * These.swap(These.toBoth("warn", 5)); // Both(5, "warn")
208
+ * ```
209
+ */
210
+ These.swap = (data) => {
211
+ if (These.isErr(data))
212
+ return These.toOk(data.error);
213
+ if (These.isOk(data))
214
+ return These.toErr(data.value);
215
+ return These.toBoth(data.value, data.error);
216
+ };
217
+ /**
218
+ * Converts a These to an Option.
219
+ * Ok and Both produce Some; Err produces None.
220
+ *
221
+ * @example
222
+ * ```ts
223
+ * These.toOption(These.toOk(42)); // Some(42)
224
+ * These.toOption(These.toBoth("warn", 42)); // Some(42)
225
+ * These.toOption(These.toErr("err")); // None
226
+ * ```
227
+ */
228
+ These.toOption = (data) => These.hasValue(data) ? { kind: "Some", value: data.value } : { kind: "None" };
229
+ /**
230
+ * Converts a These to a Result, discarding any warning from Both.
231
+ * Ok and Both produce Ok; Err produces Err.
232
+ *
233
+ * @example
234
+ * ```ts
235
+ * These.toResult(These.toOk(42)); // Ok(42)
236
+ * These.toResult(These.toBoth("warn", 42)); // Ok(42)
237
+ * These.toResult(These.toErr("err")); // Err("err")
238
+ * ```
239
+ */
240
+ These.toResult = (data) => {
241
+ if (These.hasValue(data))
242
+ return Result_js_1.Result.toOk(data.value);
243
+ return data;
244
+ };
245
+ })(These || (exports.These = These = {}));
@@ -20,5 +20,8 @@ __exportStar(require("./Rec.js"), exports);
20
20
  __exportStar(require("./RemoteData.js"), exports);
21
21
  __exportStar(require("./Result.js"), exports);
22
22
  __exportStar(require("./Task.js"), exports);
23
+ __exportStar(require("./TaskOption.js"), exports);
23
24
  __exportStar(require("./TaskResult.js"), exports);
25
+ __exportStar(require("./TaskValidation.js"), exports);
26
+ __exportStar(require("./These.js"), exports);
24
27
  __exportStar(require("./Validation.js"), exports);
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Brand = void 0;
4
+ var Brand;
5
+ (function (Brand) {
6
+ /**
7
+ * Creates a branding constructor for brand K over type T.
8
+ * The resulting function performs an unchecked cast — only use when the raw
9
+ * value is known to satisfy the brand's invariants.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * type PositiveNumber = Brand<"PositiveNumber", number>;
14
+ * const toPositiveNumber = Brand.make<"PositiveNumber", number>();
15
+ *
16
+ * const n: PositiveNumber = toPositiveNumber(42);
17
+ * ```
18
+ */
19
+ Brand.make = () => (value) => value;
20
+ /**
21
+ * Strips the brand and returns the underlying value.
22
+ * Since Brand<K, T> extends T this is rarely needed, but can improve readability.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const userId: UserId = toUserId("user-123");
27
+ * const raw: string = Brand.unwrap(userId); // "user-123"
28
+ * ```
29
+ */
30
+ Brand.unwrap = (branded) => branded;
31
+ })(Brand || (exports.Brand = Brand = {}));
@@ -14,4 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Brand.js"), exports);
17
18
  __exportStar(require("./NonEmptyList.js"), exports);
@@ -0,0 +1,120 @@
1
+ import { Option } from "./Option.js";
2
+ import { Task } from "./Task.js";
3
+ import { TaskResult } from "./TaskResult.js";
4
+ /**
5
+ * A Task that resolves to an optional value.
6
+ * Combines async operations with the Option type for values that may not exist.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const findUser = (id: string): TaskOption<User> =>
11
+ * TaskOption.tryCatch(() => db.users.findById(id));
12
+ *
13
+ * pipe(
14
+ * findUser("123"),
15
+ * TaskOption.map(user => user.name),
16
+ * TaskOption.getOrElse("Unknown")
17
+ * )();
18
+ * ```
19
+ */
20
+ export type TaskOption<A> = Task<Option<A>>;
21
+ export declare namespace TaskOption {
22
+ /**
23
+ * Wraps a value in a Some inside a Task.
24
+ */
25
+ const of: <A>(value: A) => TaskOption<A>;
26
+ /**
27
+ * Creates a TaskOption that resolves to None.
28
+ */
29
+ const none: <A = never>() => TaskOption<A>;
30
+ /**
31
+ * Lifts an Option into a TaskOption.
32
+ */
33
+ const fromOption: <A>(option: Option<A>) => TaskOption<A>;
34
+ /**
35
+ * Lifts a Task into a TaskOption by wrapping its result in Some.
36
+ */
37
+ const fromTask: <A>(task: Task<A>) => TaskOption<A>;
38
+ /**
39
+ * Creates a TaskOption from a Promise-returning function.
40
+ * Returns Some if the promise resolves, None if it rejects.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const fetchUser = TaskOption.tryCatch(() =>
45
+ * fetch("/user/1").then(r => r.json())
46
+ * );
47
+ * ```
48
+ */
49
+ const tryCatch: <A>(f: () => Promise<A>) => TaskOption<A>;
50
+ /**
51
+ * Transforms the value inside a TaskOption.
52
+ */
53
+ const map: <A, B>(f: (a: A) => B) => (data: TaskOption<A>) => TaskOption<B>;
54
+ /**
55
+ * Chains TaskOption computations. If the first resolves to Some, passes the
56
+ * value to f. If the first resolves to None, propagates None.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * pipe(
61
+ * findUser("123"),
62
+ * TaskOption.chain(user => findOrg(user.orgId))
63
+ * )();
64
+ * ```
65
+ */
66
+ const chain: <A, B>(f: (a: A) => TaskOption<B>) => (data: TaskOption<A>) => TaskOption<B>;
67
+ /**
68
+ * Applies a function wrapped in a TaskOption to a value wrapped in a TaskOption.
69
+ * Both Tasks run in parallel.
70
+ */
71
+ const ap: <A>(arg: TaskOption<A>) => <B>(data: TaskOption<(a: A) => B>) => TaskOption<B>;
72
+ /**
73
+ * Extracts a value from a TaskOption by providing handlers for both cases.
74
+ */
75
+ const fold: <A, B>(onNone: () => B, onSome: (a: A) => B) => (data: TaskOption<A>) => Task<B>;
76
+ /**
77
+ * Pattern matches on a TaskOption, returning a Task of the result.
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * pipe(
82
+ * findUser("123"),
83
+ * TaskOption.match({
84
+ * some: user => `Hello, ${user.name}`,
85
+ * none: () => "User not found"
86
+ * })
87
+ * )();
88
+ * ```
89
+ */
90
+ const match: <A, B>(cases: {
91
+ none: () => B;
92
+ some: (a: A) => B;
93
+ }) => (data: TaskOption<A>) => Task<B>;
94
+ /**
95
+ * Returns the value or a default if the TaskOption resolves to None.
96
+ */
97
+ const getOrElse: <A>(defaultValue: A) => (data: TaskOption<A>) => Task<A>;
98
+ /**
99
+ * Executes a side effect on the value without changing the TaskOption.
100
+ * Useful for logging or debugging.
101
+ */
102
+ const tap: <A>(f: (a: A) => void) => (data: TaskOption<A>) => TaskOption<A>;
103
+ /**
104
+ * Filters the value inside a TaskOption. Returns None if the predicate fails.
105
+ */
106
+ const filter: <A>(predicate: (a: A) => boolean) => (data: TaskOption<A>) => TaskOption<A>;
107
+ /**
108
+ * Converts a TaskOption to a TaskResult, using onNone to produce the error value.
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * pipe(
113
+ * findUser("123"),
114
+ * TaskOption.toTaskResult(() => "User not found")
115
+ * );
116
+ * ```
117
+ */
118
+ const toTaskResult: <E>(onNone: () => E) => <A>(data: TaskOption<A>) => TaskResult<E, A>;
119
+ }
120
+ //# sourceMappingURL=TaskOption.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TaskOption.d.ts","sourceRoot":"","sources":["../../../src/src/Core/TaskOption.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAE5C,yBAAiB,UAAU,CAAC;IAC1B;;OAEG;IACI,MAAM,EAAE,GAAI,CAAC,EAAE,OAAO,CAAC,KAAG,UAAU,CAAC,CAAC,CAA8B,CAAC;IAE5E;;OAEG;IACI,MAAM,IAAI,GAAI,CAAC,GAAG,KAAK,OAAK,UAAU,CAAC,CAAC,CAA6B,CAAC;IAE7E;;OAEG;IACI,MAAM,UAAU,GAAI,CAAC,EAAE,QAAQ,MAAM,CAAC,CAAC,CAAC,KAAG,UAAU,CAAC,CAAC,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