ok-fp 0.2.2 → 0.3.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.
@@ -0,0 +1,1328 @@
1
+ //#region src/option/model.d.ts
2
+ type Some<T> = {
3
+ some: T;
4
+ };
5
+ type None = symbol;
6
+ type OptionValue<T> = Some<T> | None;
7
+ declare const NONE: unique symbol;
8
+ //#endregion
9
+ //#region src/option/option.d.ts
10
+ type Option$1<T> = {
11
+ /**
12
+ * Filters the Option based on a predicate function.
13
+ * If this Option is Some and the predicate returns true, returns this Option.
14
+ * Otherwise, returns None.
15
+ *
16
+ * @param predicate - Function that tests the contained value
17
+ * @returns The same Option if predicate passes, None otherwise
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * some(5).filter(x => x > 3) // Some(5)
22
+ * some(2).filter(x => x > 3) // None
23
+ * none().filter(x => x > 3) // None
24
+ * ```
25
+ */
26
+ filter: (predicate: (value: T) => boolean) => Option$1<T>;
27
+ /**
28
+ * Transforms the value inside the Option using a mapping function.
29
+ * If this Option is None, returns None without calling the mapper.
30
+ *
31
+ * @param mapper - Function to transform the contained value
32
+ * @returns New Option containing the transformed value, or None
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * some(5).map(x => x * 2) // Some(10)
37
+ * none<number>().map(x => x * 2) // None
38
+ * ```
39
+ */
40
+ map: <U>(mapper: (value: T) => U) => Option$1<U>;
41
+ /**
42
+ * Returns this Option if it contains a value, otherwise returns the fallback Option.
43
+ * The fallback is lazily evaluated to avoid unnecessary computation.
44
+ *
45
+ * @param fallback - Function that provides the alternative Option
46
+ * @returns This Option if Some, otherwise the fallback Option
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * some(5).orElse(() => some(10)) // Some(5)
51
+ * none().orElse(() => some(10)) // Some(10)
52
+ * ```
53
+ */
54
+ orElse: (fallback: () => Option$1<T>) => Option$1<T>;
55
+ /**
56
+ * Applies a function wrapped in an Option to a value wrapped in an Option.
57
+ * This is useful for applying functions that are also optional.
58
+ *
59
+ * @param optA - Option containing the argument to apply the function to
60
+ * @returns Option containing the result, or None if either Option is None
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * const add = (x: number) => (y: number) => x + y;
65
+ * some(add(5)).ap(some(3)) // Some(8)
66
+ * some(add(5)).ap(none()) // None
67
+ * none().ap(some(3)) // None
68
+ * ```
69
+ */
70
+ ap: <A, U>(this: Option$1<(arg: A) => U>, optA: Option$1<A>) => Option$1<U>;
71
+ /**
72
+ * Combines this Option with another Option into a tuple.
73
+ * If both Options contain values, returns Some containing a tuple of both values.
74
+ * If either Option is None, returns None.
75
+ *
76
+ * @param optA - The Option to combine with this one
77
+ * @returns Option containing a tuple of both values, or None if either is None
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * const name = some("Alice");
82
+ * const age = some(30);
83
+ * name.zip(age) // Some(["Alice", 30])
84
+ *
85
+ * const missing = none<number>();
86
+ * name.zip(missing) // None
87
+ * none().zip(age) // None
88
+ * ```
89
+ */
90
+ zip: <A>(optA: Option$1<A>) => Option$1<readonly [T, A]>;
91
+ /**
92
+ * Flattens a nested Option structure by removing one level of nesting.
93
+ * If this Option contains another Option, returns the inner Option.
94
+ * If this Option is None, returns None.
95
+ *
96
+ * @returns The inner Option if this Option contains one, or None
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * some(some(5)).flatten() // Some(5)
101
+ * some(none<number>()).flatten() // None
102
+ * ```
103
+ */
104
+ flatten: <U>(this: Option$1<Option$1<U>>) => Option$1<U>;
105
+ /**
106
+ * Chains Option-returning operations together (monadic bind).
107
+ * If this Option is Some, applies the mapper and returns the result.
108
+ * If this Option is None, returns None without calling the mapper.
109
+ *
110
+ * @param mapper - Function that returns an Option
111
+ * @returns The Option returned by mapper, or None
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * const safeDivide = (x: number) => x === 0 ? none() : some(10 / x);
116
+ * some(2).flatMap(safeDivide) // Some(5)
117
+ * some(0).flatMap(safeDivide) // None
118
+ * none().flatMap(safeDivide) // None
119
+ * ```
120
+ */
121
+ flatMap: <U>(mapper: (value: T) => Option$1<U>) => Option$1<U>;
122
+ /**
123
+ * Performs a side effect if this Option contains a value.
124
+ * Returns the original Option unchanged.
125
+ *
126
+ * @returns The same Option instance
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * some(5).tap((value) => console.log("Has value", value)) // Some(5), logs message
131
+ * none().tap((value) => console.log("Has value", value)) // None, no log
132
+ * ```
133
+ */
134
+ tap: (sideEffect: (value: T) => unknown) => Option$1<T>;
135
+ /**
136
+ * Performs a side effect if this Option is None.
137
+ * Returns the original Option unchanged.
138
+ *
139
+ * @returns The same Option instance
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * some(5).tapNone(() => console.log("No value")) // Some(5), no log
144
+ * none().tapNone(() => console.log("No value")) // None, logs message
145
+ * ```
146
+ */
147
+ tapNone: (sideEffect: () => unknown) => Option$1<T>;
148
+ /**
149
+ * Pattern matches on the Option, executing different functions based on its state.
150
+ *
151
+ * @param onNone - Function to execute if Option is None
152
+ * @param onSome - Function to execute if Option is Some
153
+ * @returns The result of the executed function
154
+ *
155
+ * @example
156
+ * ```typescript
157
+ * some(5).match(() => "empty", x => `value: ${x}`) // "value: 5"
158
+ * none().match(() => "empty", x => `value: ${x}`) // "empty"
159
+ * ```
160
+ */
161
+ match: <U>(onNone: () => U, onSome: (value: T) => U) => U;
162
+ /**
163
+ * Extracts the value from the Option, or returns a fallback value if None.
164
+ *
165
+ * @param fallback - Function that provides the default value
166
+ * @returns The value or the fallback value
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * some(5).getOrElse(() => 0) // 5
171
+ * none().getOrElse(() => 0) // 0
172
+ * ```
173
+ */
174
+ getOrElse: (fallback: () => T) => T;
175
+ /**
176
+ * Converts the Option to a nullable value.
177
+ * Returns the contained value if Some, or null if None.
178
+ *
179
+ * @returns The value or null
180
+ *
181
+ * @example
182
+ * ```typescript
183
+ * some(5).toNullable() // 5
184
+ * none().toNullable() // null
185
+ * ```
186
+ */
187
+ toNullable: () => T | null;
188
+ /**
189
+ * Converts the Option to an array.
190
+ * If this Option contains a value, returns an array with that single value.
191
+ * If this Option is None, returns an empty array.
192
+ *
193
+ * @returns Array containing the value if Some, or empty array if None
194
+ *
195
+ * @example
196
+ * ```typescript
197
+ * some(42).toArray() // [42]
198
+ * none().toArray() // []
199
+ * ```
200
+ */
201
+ toArray: () => readonly T[];
202
+ };
203
+ //#endregion
204
+ //#region src/either/model.d.ts
205
+ type Left<E> = {
206
+ readonly left: E;
207
+ };
208
+ type Right<T> = {
209
+ readonly right: T;
210
+ };
211
+ type EitherValue<E, T> = Left<E> | Right<T>;
212
+ type EitherResult<E, T> = {
213
+ ok: true;
214
+ value: T;
215
+ } | {
216
+ ok: false;
217
+ error: E;
218
+ };
219
+ //#endregion
220
+ //#region src/either/either.d.ts
221
+ type Either$1<E, T> = {
222
+ /**
223
+ * Filters the Either based on a predicate function applied to the Right value.
224
+ *
225
+ * @param predicate - Function that tests the Right value
226
+ * @param onLeft - Function that provides the error value when predicate fails
227
+ * @returns The same Either if Left or predicate passes, otherwise Left with the provided error
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * const isPositive = (n: number) => n > 0;
232
+ * right(5).filterOrElse(isPositive, () => "Must be positive") // Right(5)
233
+ * right(-3).filterOrElse(isPositive, () => "Must be positive") // Left("Must be positive")
234
+ * left("error").filterOrElse(isPositive, () => "Must be positive") // Left("error")
235
+ * ```
236
+ */
237
+ filterOrElse: (predicate: (right: T) => boolean, onLeft: () => E) => Either$1<E, T>;
238
+ /**
239
+ * Transforms the Right value using a mapping function.
240
+ *
241
+ * @typeParam U - The type of the transformed value
242
+ * @param mapper - Function to transform the Right value
243
+ * @returns New Either with the transformed Right value, or the same Left if error
244
+ *
245
+ * @example
246
+ * ```typescript
247
+ * right(5).map(x => x * 2) // Right(10)
248
+ * left("error").map(x => x * 2) // Left("error")
249
+ * ```
250
+ */
251
+ map: <U>(mapper: (right: T) => U) => Either$1<E, U>;
252
+ /**
253
+ * Returns this Either if it's Right, otherwise returns the result of the fallback function.
254
+ *
255
+ * @typeParam EE - The type of the error in the fallback Either
256
+ * @param fallback - Function that takes the Left value and returns an alternative Either
257
+ * @returns This Either if Right, otherwise the Either returned by the fallback function
258
+ *
259
+ * @example
260
+ * ```typescript
261
+ * right(42).orElse((err) => right(0)) // Right(42)
262
+ * left("error").orElse((err) => right(0)) // Right(0)
263
+ * ```
264
+ */
265
+ orElse: <EE>(fallback: (left: E) => Either$1<EE, T>) => Either$1<E | EE, T>;
266
+ /**
267
+ * Applies a function wrapped in an Either to a value wrapped in an Either.
268
+ *
269
+ * @typeParam A - The type of the argument value
270
+ * @typeParam U - The type of the function's return value
271
+ * @param arg - Either containing the argument to apply the function to
272
+ * @returns Either containing the function result, or the first Left if any Either is Left
273
+ *
274
+ * @example
275
+ * ```typescript
276
+ * const add = (x: number) => (y: number) => x + y;
277
+ * right(add(5)).ap(right(3)) // Right(8)
278
+ * right(add(5)).ap(left("err")) // Left("err")
279
+ * left("err").ap(right(3)) // Left("err")
280
+ * ```
281
+ */
282
+ ap: <EE, A, U>(this: Either$1<E, (a: A) => U>, arg: Either$1<EE, A>) => Either$1<E | EE, U>;
283
+ /**
284
+ * Swaps the Left and Right sides of the Either.
285
+ *
286
+ * @returns Either with Left and Right sides swapped
287
+ *
288
+ * @example
289
+ * ```typescript
290
+ * right(42).swap() // Left(42)
291
+ * left("error").swap() // Right("error")
292
+ * ```
293
+ */
294
+ swap: () => Either$1<T, E>;
295
+ /**
296
+ * Combines this Either with another Either into a tuple.
297
+ *
298
+ * @typeParam EE - Left type of the Either to combine with
299
+ * @typeParam A - Right type of the Either to combine with
300
+ * @param eitherA - The Either to combine with this one
301
+ * @returns Either containing a tuple of both Right values, or the first Left if any Either is Left
302
+ *
303
+ * @example
304
+ * ```typescript
305
+ * right("Alice").zip(right(30)) // Right(["Alice", 30])
306
+ * right("Alice").zip(left("No age")) // Left("No age")
307
+ * left("No name").zip(right(30)) // Left("No name")
308
+ * ```
309
+ */
310
+ zip: <EE, A>(eitherA: Either$1<EE, A>) => Either$1<E | EE, readonly [T, A]>;
311
+ /**
312
+ * Flattens a nested Either structure by removing one level of nesting.
313
+ *
314
+ * @typeParam EE - Left type of the inner Either
315
+ * @typeParam U - Right type of the inner Either
316
+ * @returns The inner Either if this Either is Right, otherwise this Either unchanged
317
+ *
318
+ * @example
319
+ * ```typescript
320
+ * right(right(42)).flatten() // Right(42)
321
+ * right(left("inner error")).flatten() // Left("inner error")
322
+ *
323
+ * ```
324
+ */
325
+ flatten: <EE, U>(this: Either$1<E, Either$1<EE, U>>) => Either$1<E | EE, U>;
326
+ /**
327
+ * Chains Either-returning operations together (monadic bind).
328
+ *
329
+ * @typeParam EE - The error type of the Either returned by the mapper
330
+ * @typeParam U - The success type of the Either returned by the mapper
331
+ * @param mapper - Function that takes a Right value and returns an Either
332
+ * @returns The Either returned by mapper if this Either is Right, otherwise this Either unchanged
333
+ *
334
+ * @example
335
+ * ```typescript
336
+ * const safeDivide = (x: number, y: number) =>
337
+ * y === 0 ? left("Division by zero") : right(x / y);
338
+ *
339
+ * right(10).flatMap(x => safeDivide(x, 2)) // Right(5)
340
+ * right(10).flatMap(x => safeDivide(x, 0)) // Left("Division by zero")
341
+ * left("error").flatMap(x => safeDivide(x, 2)) // Left("error") - mapper not called
342
+ * ```
343
+ */
344
+ flatMap: <EE, U>(mapper: (right: T) => Either$1<EE, U>) => Either$1<E | EE, U>;
345
+ /**
346
+ * Performs a side effect if this Either is Right, returning the original Either unchanged.
347
+ * If this Either is Left, the side effect is not executed and the Either is returned as-is.
348
+ *
349
+ * @param sideEffect - Function to execute with the Right value (return value is ignored)
350
+ * @returns The same Either instance unchanged
351
+ *
352
+ * @example
353
+ * ```typescript
354
+ * right(42)
355
+ * .tap(value => console.log(`Got value: ${value}`)) // Logs: "Got value: 42"
356
+ * left("error")
357
+ * .tap(value => console.log(`Got value: ${value}`)) // No log output
358
+ *
359
+ * ```
360
+ */
361
+ tap: (sideEffect: (right: T) => void) => Either$1<E, T>;
362
+ /**
363
+ * Pattern matches on the Either, executing different functions based on its state.
364
+ *
365
+ * @typeParam U - The return type of both matcher functions
366
+ * @param onLeft - Function to execute if Either is Left, receives the Left value
367
+ * @param onRight - Function to execute if Either is Right, receives the Right value
368
+ * @returns The result of the executed function
369
+ *
370
+ * @example
371
+ * ```typescript
372
+ * right(42).match(
373
+ * (err) => `Error: ${err}`,
374
+ * (val) => `Value: ${val}`
375
+ * ) // "Value: 42"
376
+ *
377
+ * left("Not a number").match(
378
+ * (err) => `Error: ${err}`,
379
+ * (val) => `Value: ${val}`
380
+ * ) // "Error: Not a number"
381
+ * ```
382
+ */
383
+ match: <U>(onLeft: (left: E) => U, onRight: (right: T) => U) => U;
384
+ /**
385
+ * Extracts the Right value from the Either, or returns a fallback value if Left.
386
+ *
387
+ * @param fallback - Function that takes the Left value and returns a default value of type T
388
+ * @returns The Right value if present, otherwise the result of the fallback function
389
+ *
390
+ * @example
391
+ * ```typescript
392
+ * right(42).getOrElse((err) => 0) // 42
393
+ * left("error").getOrElse((err) => 0) // 0
394
+ * ```
395
+ */
396
+ getOrElse: (fallback: (left: E) => T) => T;
397
+ /**
398
+ * Converts the Either to a Result type, which is an object with `ok` and `error` or `value` properties.
399
+ *
400
+ * @returns A Result object representing the Either's state
401
+ *
402
+ * @example
403
+ * ```typescript
404
+ * const result = right(42).toResult();
405
+ * console.log(result.ok); // true
406
+ * console.log(result.value); // 42
407
+ *
408
+ * const errorResult = left("error").toResult();
409
+ * console.log(errorResult.ok); // false
410
+ * console.log(errorResult.error); // "error"
411
+ * ```
412
+ */
413
+ toResult: () => EitherResult<E, T>;
414
+ };
415
+ //#endregion
416
+ //#region src/either/constructors.d.ts
417
+ /**
418
+ * Creates an Either containing an error value (Left).
419
+ *
420
+ * @typeParam E - The type of the error value
421
+ * @typeParam T - The type of the success value (defaults to never since this is an error)
422
+ * @param left - The error value to wrap
423
+ * @returns Either containing the error value on the Left side
424
+ *
425
+ * @example
426
+ * ```typescript
427
+ * const error = left("Something went wrong"); // Either<string, never>
428
+ * ```
429
+ */
430
+ declare function left<E, T = never>(left: E): Either$1<E, T>;
431
+ /**
432
+ * Creates an Either containing a success value (Right).
433
+ *
434
+ * @typeParam T - The type of the success value
435
+ * @typeParam E - The type of the error value (defaults to never since this is a success)
436
+ * @param right - The success value to wrap
437
+ * @returns Either containing the success value on the Right side
438
+ *
439
+ * @example
440
+ * ```typescript
441
+ * const success = right(42); // Either<never, number>
442
+ * ```
443
+ */
444
+ declare function right<T, E = never>(right: T): Either$1<E, T>;
445
+ /**
446
+ * Creates an Either from a potentially nullable value.
447
+ * If the value is null or undefined, creates a Left with the provided error.
448
+ * If the value is present, creates a Right with the value.
449
+ *
450
+ * @typeParam E - The type of the error value
451
+ * @typeParam T - The type of the success value
452
+ * @param nullable - The potentially null/undefined value
453
+ * @param onNullish - Function that provides the error value when nullable is null/undefined
454
+ * @returns Either containing the value if present, or the error if null/undefined
455
+ *
456
+ * @example
457
+ * ```typescript
458
+ * fromNullable("hello", () => "empty") // Right("hello")
459
+ * fromNullable(null, () => "empty") // Left("empty")
460
+ * fromNullable(undefined, () => "empty") // Left("empty")
461
+ * ```
462
+ */
463
+ declare function fromNullable$1<E, T>(nullable: T | null | undefined, onNullish: () => E): Either$1<E, T>;
464
+ /**
465
+ * Safely executes a function that might throw, converting exceptions to Either.
466
+ *
467
+ * @typeParam E - The type of the processed error value
468
+ * @typeParam T - The type of the success value
469
+ * @param fn - The function to execute that might throw
470
+ * @param onThrow - Function that processes the caught error into the desired error type
471
+ * @returns Either containing the result if successful, or the processed error if thrown
472
+ *
473
+ * @example
474
+ * ```typescript
475
+ * const parseNumber = (str: string) =>
476
+ * tryCatch(
477
+ * () => JSON.parse(str),
478
+ * (err) => `Parse error: ${err.message}`
479
+ * );
480
+ *
481
+ * parseNumber("42") // Right(42)
482
+ * parseNumber("invalid") // Left("Parse error: ...")
483
+ * ```
484
+ */
485
+ declare function tryCatch$1<E, T>(fn: () => T, onThrow: (err: unknown) => E): Either$1<E, T>;
486
+ /**
487
+ * Creates an Either from an Option by providing an error value for the None case.
488
+ *
489
+ * @typeParam E - The type of the error value
490
+ * @typeParam T - The type of the success value
491
+ * @param opt - The Option to convert
492
+ * @param onNone - Function that provides the error value when Option is None
493
+ * @returns Either containing the Option's value if Some, or the error if None
494
+ *
495
+ * @example
496
+ * ```typescript
497
+ * fromOption(some(42), () => "empty") // Right(42)
498
+ * fromOption(none(), () => "empty") // Left("empty")
499
+ * ```
500
+ */
501
+ declare function fromOption$1<E, T>(opt: Option$1<T>, onNone: () => E): Either$1<E, T>;
502
+ //#endregion
503
+ //#region src/either/helpers.d.ts
504
+ /**
505
+ * Converts an array of Eithers into an Either of array.
506
+ * Returns Right with all values if all Eithers are Right, otherwise the first Left.
507
+ *
508
+ * @param eithers - Array of Eithers to sequence
509
+ * @returns Either containing array of all values, or the first Left
510
+ *
511
+ * @example
512
+ * ```typescript
513
+ * sequence([right(1), right(2), right(3)]) // Right([1, 2, 3])
514
+ * sequence([right(1), left("error")]) // Left("error")
515
+ * ```
516
+ */
517
+ declare function sequence$2<E, T>(eithers: Either$1<E, T>[]): Either$1<E, T[]>;
518
+ //#endregion
519
+ //#region src/either/index.d.ts
520
+ type Either<E, T> = Either$1<E, T>;
521
+ declare const Either: {
522
+ fromNullable: typeof fromNullable$1;
523
+ fromOption: typeof fromOption$1;
524
+ tryCatch: typeof tryCatch$1;
525
+ sequence: typeof sequence$2;
526
+ };
527
+ //#endregion
528
+ //#region src/task/model.d.ts
529
+ type TaskValue<T> = () => Promise<T>;
530
+ //#endregion
531
+ //#region src/task/task.d.ts
532
+ type Task$1<T> = {
533
+ /**
534
+ * Transforms the value produced by the Task using a mapping function.
535
+ *
536
+ * @typeParam U - The type of the transformed value
537
+ * @param mapper - Function to transform the resolved value
538
+ * @returns A new Task that resolves with the transformed value
539
+ *
540
+ * @example
541
+ * ```typescript
542
+ * task(5).map(x => x * 2).run() // Promise<10>
543
+ * ```
544
+ */
545
+ map: <U>(mapper: (value: T) => U) => Task$1<U>;
546
+ /**
547
+ * Applies a function wrapped in a Task to a value wrapped in a Task.
548
+ * Both Tasks are run concurrently.
549
+ *
550
+ * @typeParam A - The type of the argument value
551
+ * @typeParam U - The type of the function's return value
552
+ * @param arg - Task containing the argument to apply the function to
553
+ * @returns Task containing the function result
554
+ *
555
+ * @example
556
+ * ```typescript
557
+ * const add = (x: number) => (y: number) => x + y;
558
+ * task(add(5)).ap(task(3)).run() // Promise<8>
559
+ * ```
560
+ */
561
+ ap: <A, U>(this: Task$1<(a: A) => U>, arg: Task$1<A>) => Task$1<U>;
562
+ /**
563
+ * Combines this Task with another Task into a tuple.
564
+ * Both Tasks are run concurrently.
565
+ *
566
+ * @typeParam A - The type of the value in the other Task
567
+ * @param taskA - The Task to combine with this one
568
+ * @returns Task containing a tuple of both values
569
+ *
570
+ * @example
571
+ * ```typescript
572
+ * task("Alice").zip(task(30)).run() // Promise<["Alice", 30]>
573
+ * ```
574
+ */
575
+ zip: <A>(taskA: Task$1<A>) => Task$1<readonly [T, A]>;
576
+ /**
577
+ * Flattens a nested Task structure by removing one level of nesting.
578
+ *
579
+ * @returns The inner Task result
580
+ *
581
+ * @example
582
+ * ```typescript
583
+ * task(task(42)).flatten().run() // Promise<42>
584
+ * ```
585
+ */
586
+ flatten: <U>(this: Task$1<Task$1<U>>) => Task$1<U>;
587
+ /**
588
+ * Chains Task-returning operations together (monadic bind).
589
+ *
590
+ * @typeParam U - The type of the value in the returned Task
591
+ * @param mapper - Function that takes a resolved value and returns a Task
592
+ * @returns The Task returned by mapper
593
+ *
594
+ * @example
595
+ * ```typescript
596
+ * task(10).flatMap(x => task(x * 2)).run() // Promise<20>
597
+ * ```
598
+ */
599
+ flatMap: <U>(mapper: (value: T) => Task$1<U>) => Task$1<U>;
600
+ /**
601
+ * Performs a side effect with the resolved value, returning the original Task unchanged.
602
+ *
603
+ * @param sideEffect - Function to execute with the resolved value (return value is ignored)
604
+ * @returns The same Task instance unchanged
605
+ *
606
+ * @example
607
+ * ```typescript
608
+ * task(42)
609
+ * .tap(value => console.log(`Got value: ${value}`))
610
+ * .run() // Logs: "Got value: 42", resolves to 42
611
+ * ```
612
+ */
613
+ tap: (sideEffect: (value: T) => unknown) => Task$1<T>;
614
+ /**
615
+ * Executes the Task and returns the resulting Promise.
616
+ *
617
+ * @returns A Promise that resolves with the Task's value
618
+ *
619
+ * @example
620
+ * ```typescript
621
+ * const result = await task(42).run(); // 42
622
+ * ```
623
+ */
624
+ run: () => Promise<T>;
625
+ };
626
+ //#endregion
627
+ //#region src/taskEither/model.d.ts
628
+ type TaskEitherValue<E, T> = () => Promise<Either$1<E, T>>;
629
+ //#endregion
630
+ //#region src/taskEither/taskEither.d.ts
631
+ type TaskEither$1<E, T> = {
632
+ /**
633
+ * Transforms the Right value using a mapping function.
634
+ * If this TaskEither resolves to Left, the mapper is not called.
635
+ *
636
+ * @typeParam U - The type of the transformed value
637
+ * @param mapper - Function to transform the Right value
638
+ * @returns New TaskEither with the transformed Right value, or the same Left if error
639
+ *
640
+ * @example
641
+ * ```typescript
642
+ * taskRight(5).map(x => x * 2).run() // Promise<Right(10)>
643
+ * taskLeft("error").map(x => x * 2).run() // Promise<Left("error")>
644
+ * ```
645
+ */
646
+ map: <U>(mapper: (right: T) => U) => TaskEither$1<E, U>;
647
+ /**
648
+ * Transforms the Left value using a mapping function.
649
+ * If this TaskEither resolves to Right, the mapper is not called.
650
+ *
651
+ * @typeParam F - The type of the transformed error
652
+ * @param mapper - Function to transform the Left value
653
+ * @returns New TaskEither with the transformed Left value, or the same Right if success
654
+ *
655
+ * @example
656
+ * ```typescript
657
+ * taskLeft("error").mapLeft(e => `mapped: ${e}`).run() // Promise<Left("mapped: error")>
658
+ * taskRight(42).mapLeft(e => `mapped: ${e}`).run() // Promise<Right(42)>
659
+ * ```
660
+ */
661
+ mapLeft: <F>(mapper: (left: E) => F) => TaskEither$1<F, T>;
662
+ /**
663
+ * Applies a function wrapped in a TaskEither to a value wrapped in a TaskEither.
664
+ * Both TaskEithers are run concurrently.
665
+ *
666
+ * @typeParam EE - Left type of the argument TaskEither
667
+ * @typeParam A - The type of the argument value
668
+ * @typeParam U - The type of the function's return value
669
+ * @param arg - TaskEither containing the argument to apply the function to
670
+ * @returns TaskEither containing the function result, or the first Left if any is Left
671
+ *
672
+ * @example
673
+ * ```typescript
674
+ * const add = (x: number) => (y: number) => x + y;
675
+ * taskRight(add(5)).ap(taskRight(3)).run() // Promise<Right(8)>
676
+ * taskRight(add(5)).ap(taskLeft("err")).run() // Promise<Left("err")>
677
+ * ```
678
+ */
679
+ ap: <EE, A, U>(this: TaskEither$1<E, (a: A) => U>, arg: TaskEither$1<EE, A>) => TaskEither$1<E | EE, U>;
680
+ /**
681
+ * Combines this TaskEither with another TaskEither into a tuple.
682
+ * Both TaskEithers are run concurrently.
683
+ *
684
+ * @typeParam EE - Left type of the other TaskEither
685
+ * @typeParam A - Right type of the other TaskEither
686
+ * @param other - The TaskEither to combine with this one
687
+ * @returns TaskEither containing a tuple of both Right values, or the first Left
688
+ *
689
+ * @example
690
+ * ```typescript
691
+ * taskRight("Alice").zip(taskRight(30)).run() // Promise<Right(["Alice", 30])>
692
+ * taskRight("Alice").zip(taskLeft("No age")).run() // Promise<Left("No age")>
693
+ * ```
694
+ */
695
+ zip: <EE, A>(other: TaskEither$1<EE, A>) => TaskEither$1<E | EE, readonly [T, A]>;
696
+ /**
697
+ * Flattens a nested TaskEither structure by removing one level of nesting.
698
+ *
699
+ * @typeParam EE - Left type of the inner TaskEither
700
+ * @typeParam U - Right type of the inner TaskEither
701
+ * @returns The inner TaskEither if this TaskEither is Right, otherwise this Left unchanged
702
+ *
703
+ * @example
704
+ * ```typescript
705
+ * taskRight(taskRight(42)).flatten().run() // Promise<Right(42)>
706
+ * taskRight(taskLeft("inner error")).flatten().run() // Promise<Left("inner error")>
707
+ * ```
708
+ */
709
+ flatten: <EE, U>(this: TaskEither$1<E, TaskEither$1<EE, U>>) => TaskEither$1<E | EE, U>;
710
+ /**
711
+ * Chains TaskEither-returning operations together (monadic bind).
712
+ * If this TaskEither resolves to Left, the mapper is not called.
713
+ *
714
+ * @typeParam EE - The error type of the TaskEither returned by the mapper
715
+ * @typeParam U - The success type of the TaskEither returned by the mapper
716
+ * @param mapper - Function that takes a Right value and returns a TaskEither
717
+ * @returns The TaskEither returned by mapper if this is Right, otherwise this Left unchanged
718
+ *
719
+ * @example
720
+ * ```typescript
721
+ * taskRight(10).flatMap(x => taskRight(x * 2)).run() // Promise<Right(20)>
722
+ * taskLeft("error").flatMap(x => taskRight(x)).run() // Promise<Left("error")>
723
+ * ```
724
+ */
725
+ flatMap: <EE, U>(mapper: (right: T) => TaskEither$1<EE, U>) => TaskEither$1<E | EE, U>;
726
+ /**
727
+ * Performs a side effect with the Right value, returning the original TaskEither unchanged.
728
+ * If this TaskEither resolves to Left, the side effect is not executed.
729
+ *
730
+ * @param sideEffect - Function to execute with the Right value (return value is ignored)
731
+ * @returns The same TaskEither instance unchanged
732
+ *
733
+ * @example
734
+ * ```typescript
735
+ * taskRight(42).tap(v => console.log(v)).run() // Logs: 42, resolves to Right(42)
736
+ * taskLeft("error").tap(v => console.log(v)).run() // No log, resolves to Left("error")
737
+ * ```
738
+ */
739
+ tap: (sideEffect: (right: T) => unknown) => TaskEither$1<E, T>;
740
+ /**
741
+ * Performs a side effect with the Left value, returning the original TaskEither unchanged.
742
+ * If this TaskEither resolves to Right, the side effect is not executed.
743
+ *
744
+ * @param sideEffect - Function to execute with the Left value (return value is ignored)
745
+ * @returns The same TaskEither instance unchanged
746
+ *
747
+ * @example
748
+ * ```typescript
749
+ * taskLeft("error").tapLeft(e => console.log(e)).run() // Logs: "error", resolves to Left("error")
750
+ * taskRight(42).tapLeft(e => console.log(e)).run() // No log, resolves to Right(42)
751
+ * ```
752
+ */
753
+ tapLeft: (sideEffect: (left: E) => unknown) => TaskEither$1<E, T>;
754
+ /**
755
+ * Pattern matches on the resolved Either, executing different functions based on its state.
756
+ * Returns the result wrapped in a Task.
757
+ *
758
+ * @typeParam U - The return type of both matcher functions
759
+ * @param onLeft - Function to execute if resolved Either is Left
760
+ * @param onRight - Function to execute if resolved Either is Right
761
+ * @returns Task that resolves with the result of the executed function
762
+ *
763
+ * @example
764
+ * ```typescript
765
+ * await taskRight(5).match(() => 0, x => x * 2).run() // 10
766
+ * await taskLeft("error").match(() => 0, x => x * 2).run() // 0
767
+ * ```
768
+ */
769
+ match: <U>(onLeft: (left: E) => U, onRight: (right: T) => U) => Task$1<U>;
770
+ /**
771
+ * Extracts the Right value, or returns a fallback value if Left.
772
+ * Returns the result wrapped in a Task.
773
+ *
774
+ * @param fallback - Function that takes the Left value and returns a default value of type T
775
+ * @returns Task that resolves with the Right value or the fallback
776
+ *
777
+ * @example
778
+ * ```typescript
779
+ * await taskRight(42).getOrElse(() => 0).run() // 42
780
+ * await taskLeft("error").getOrElse(() => 0).run() // 0
781
+ * ```
782
+ */
783
+ getOrElse: (fallback: (left: E) => T) => Task$1<T>;
784
+ /**
785
+ * Returns this TaskEither if it resolves to Right, otherwise returns the result of the fallback function.
786
+ *
787
+ * @typeParam EE - The type of the error in the fallback TaskEither
788
+ * @param fallback - Function that takes the Left value and returns an alternative TaskEither
789
+ * @returns This TaskEither if Right, otherwise the TaskEither returned by the fallback function
790
+ *
791
+ * @example
792
+ * ```typescript
793
+ * taskRight(42).orElse(() => taskRight(0)).run() // Promise<Right(42)>
794
+ * taskLeft("error").orElse(() => taskRight(0)).run() // Promise<Right(0)>
795
+ * ```
796
+ */
797
+ orElse: <EE>(fallback: (left: E) => TaskEither$1<EE, T>) => TaskEither$1<E | EE, T>;
798
+ /**
799
+ * Executes the TaskEither and returns the resulting Promise.
800
+ *
801
+ * @returns A Promise that resolves with the Either value
802
+ *
803
+ * @example
804
+ * ```typescript
805
+ * const result = await taskRight(42).run(); // Either<never, number>
806
+ * ```
807
+ */
808
+ run: () => Promise<Either$1<E, T>>;
809
+ };
810
+ //#endregion
811
+ //#region src/validation/model.d.ts
812
+ type Valid<T> = {
813
+ readonly valid: T;
814
+ };
815
+ type Invalid<E> = {
816
+ readonly invalid: readonly E[];
817
+ };
818
+ type ValidationValue<E, T> = Valid<T> | Invalid<E>;
819
+ type ValidationResult<E, T> = {
820
+ readonly ok: true;
821
+ readonly value: T;
822
+ } | {
823
+ readonly ok: false;
824
+ readonly errors: readonly E[];
825
+ };
826
+ //#endregion
827
+ //#region src/validation/validation.d.ts
828
+ type Validation$1<E, T> = {
829
+ /**
830
+ * Filters the Valid value based on a predicate function.
831
+ * If the predicate fails, returns Invalid with the provided error.
832
+ * If this Validation is already Invalid, returns the same Invalid unchanged.
833
+ *
834
+ * @param predicate - Function that tests the valid value
835
+ * @param onInvalid - Function that provides the error value when predicate fails
836
+ * @returns The same Validation if Invalid or predicate passes, otherwise Invalid with the provided error
837
+ *
838
+ * @example
839
+ * ```typescript
840
+ * const isPositive = (n: number) => n > 0;
841
+ * valid(5).filterOrElse(isPositive, () => "Must be positive") // Valid(5)
842
+ * valid(-3).filterOrElse(isPositive, () => "Must be positive") // Invalid(["Must be positive"])
843
+ * invalid("error").filterOrElse(isPositive, () => "Must be positive") // Invalid(["error"])
844
+ * ```
845
+ */
846
+ filterOrElse: (predicate: (value: T) => boolean, onInvalid: () => E) => Validation$1<E, T>;
847
+ /**
848
+ * Transforms the valid value using a mapping function.
849
+ * If this Validation is Invalid, returns the same Invalid unchanged.
850
+ *
851
+ * @param mapper - Function to transform the contained value
852
+ * @returns New Validation containing the transformed value, or the same Invalid
853
+ */
854
+ map: <U>(mapper: (value: T) => U) => Validation$1<E, U>;
855
+ /**
856
+ * Applies a function wrapped in a Validation to a value wrapped in a Validation.
857
+ * Unlike Either, if both are Invalid, errors are accumulated (concatenated).
858
+ *
859
+ * @param arg - Validation containing the argument to apply the function to
860
+ * @returns Validation containing the result, or accumulated errors if any are Invalid
861
+ *
862
+ * @example
863
+ * ```typescript
864
+ * const add = (x: number) => (y: number) => x + y;
865
+ * valid(add(5)).ap(valid(3)) // Valid(8)
866
+ * valid(add(5)).ap(invalid("err")) // Invalid(["err"])
867
+ * invalid("e1").ap(invalid("e2")) // Invalid(["e1", "e2"]) ← errors accumulated!
868
+ * ```
869
+ */
870
+ ap: <EE, A, U>(this: Validation$1<E, (a: A) => U>, arg: Validation$1<EE, A>) => Validation$1<E | EE, U>;
871
+ /**
872
+ * Combines this Validation with another Validation into a tuple.
873
+ * If both are Valid, returns Valid containing a tuple of both values.
874
+ * If either is Invalid, accumulates all errors.
875
+ *
876
+ * @param valA - The Validation to combine with this one
877
+ * @returns Validation containing a tuple of both values, or accumulated errors
878
+ *
879
+ * @example
880
+ * ```typescript
881
+ * valid("Alice").zip(valid(30)) // Valid(["Alice", 30])
882
+ * valid("Alice").zip(invalid("No age")) // Invalid(["No age"])
883
+ * invalid("e1").zip(invalid("e2")) // Invalid(["e1", "e2"])
884
+ * ```
885
+ */
886
+ zip: <EE, A>(valA: Validation$1<EE, A>) => Validation$1<E | EE, readonly [T, A]>;
887
+ /**
888
+ * Pattern matches on the Validation, executing different functions based on its state.
889
+ *
890
+ * @param onInvalid - Function to execute if Validation is Invalid, receives the array of errors
891
+ * @param onValid - Function to execute if Validation is Valid, receives the value
892
+ * @returns The result of the executed function
893
+ */
894
+ match: <U>(onInvalid: (errors: readonly E[]) => U, onValid: (value: T) => U) => U;
895
+ /**
896
+ * Extracts the valid value, or returns a fallback value if Invalid.
897
+ *
898
+ * @param fallback - Function that receives the errors and returns a default value
899
+ * @returns The valid value if present, otherwise the result of the fallback function
900
+ */
901
+ getOrElse: (fallback: (errors: readonly E[]) => T) => T;
902
+ /**
903
+ * Performs a side effect if this Validation is Valid, returning the original Validation unchanged.
904
+ * If this Validation is Invalid, the side effect is not executed.
905
+ *
906
+ * @param sideEffect - Function to execute with the valid value (return value is ignored)
907
+ * @returns The same Validation instance unchanged
908
+ */
909
+ tap: (sideEffect: (value: T) => void) => Validation$1<E, T>;
910
+ /**
911
+ * Performs a side effect if this Validation is Invalid, returning the original Validation unchanged.
912
+ * If this Validation is Valid, the side effect is not executed.
913
+ *
914
+ * @param sideEffect - Function to execute with the errors array (return value is ignored)
915
+ * @returns The same Validation instance unchanged
916
+ */
917
+ tapInvalid: (sideEffect: (errors: readonly E[]) => void) => Validation$1<E, T>;
918
+ /**
919
+ * Converts the Validation to a ValidationResult type.
920
+ *
921
+ * @returns A ValidationResult object representing the Validation's state
922
+ *
923
+ * @example
924
+ * ```typescript
925
+ * valid(42).toResult() // { ok: true, value: 42 }
926
+ * invalid("error").toResult() // { ok: false, errors: ["error"] }
927
+ * ```
928
+ */
929
+ toResult: () => ValidationResult<E, T>;
930
+ };
931
+ //#endregion
932
+ //#region src/helpers/map2.d.ts
933
+ /**
934
+ * Combines two Options using a mapping function.
935
+ * Only applies the mapper if both Options contain values.
936
+ *
937
+ * @param first - First Option to combine
938
+ * @param second - Second Option to combine
939
+ * @param mapper - Function that combines both values
940
+ * @returns Option containing the combined result, or None if either Option is None
941
+ *
942
+ * @example
943
+ * ```typescript
944
+ * map2(some("John"), some("Doe"), (first, last) => `Hi ${first} ${last}!`)
945
+ * // Some("John Doe")
946
+ * ```
947
+ */
948
+ declare function map2<A, B, C>(first: Option$1<A>, second: Option$1<B>, mapper: (first: A, second: B) => C): Option$1<C>;
949
+ /**
950
+ * Combines two Eithers using a mapping function.
951
+ * Returns the mapped result if both Eithers are Right, otherwise the first Left.
952
+ *
953
+ * @param first - First Either to combine
954
+ * @param second - Second Either to combine
955
+ * @param mapper - Function to combine both Right values
956
+ * @returns Either containing the combined result, or the first Left
957
+ *
958
+ * @example
959
+ * ```typescript
960
+ * map2(right("John"), right("Doe"), (first, last) => `${first} ${last}`)
961
+ * // Right("John Doe")
962
+ * ```
963
+ */
964
+ declare function map2<EA, A, EB, B, C>(first: Either$1<EA, A>, second: Either$1<EB, B>, mapper: (first: A, second: B) => C): Either$1<EA | EB, C>;
965
+ /**
966
+ * Combines two Validations using a mapping function.
967
+ * If both are Valid, applies the mapper. If any are Invalid, accumulates all errors.
968
+ *
969
+ * @param first - First Validation to combine
970
+ * @param second - Second Validation to combine
971
+ * @param mapper - Function to combine both valid values
972
+ * @returns Validation containing the combined result, or all accumulated errors
973
+ *
974
+ * @example
975
+ * ```typescript
976
+ * map2(valid("John"), valid("Doe"), (first, last) => `${first} ${last}`)
977
+ * // Valid("John Doe")
978
+ * ```
979
+ */
980
+ declare function map2<EA, A, EB, B, C>(first: Validation$1<EA, A>, second: Validation$1<EB, B>, mapper: (first: A, second: B) => C): Validation$1<EA | EB, C>;
981
+ /**
982
+ * Combines two Tasks using a mapping function.
983
+ * Runs both Tasks and maps their resolved values.
984
+ *
985
+ * @param first - First Task to combine
986
+ * @param second - Second Task to combine
987
+ * @param mapper - Function that combines both resolved values
988
+ * @returns Task containing the combined result
989
+ */
990
+ declare function map2<A, B, C>(first: Task$1<A>, second: Task$1<B>, mapper: (first: A, second: B) => C): Task$1<C>;
991
+ /**
992
+ * Combines two TaskEithers using a mapping function.
993
+ * Returns the mapped result if both resolve to Right, otherwise the first Left.
994
+ *
995
+ * @param first - First TaskEither to combine
996
+ * @param second - Second TaskEither to combine
997
+ * @param mapper - Function to combine both Right values
998
+ * @returns TaskEither containing the combined result, or the first Left
999
+ */
1000
+ declare function map2<EA, A, EB, B, C>(first: TaskEither$1<EA, A>, second: TaskEither$1<EB, B>, mapper: (first: A, second: B) => C): TaskEither$1<EA | EB, C>;
1001
+ //#endregion
1002
+ //#region src/helpers/map3.d.ts
1003
+ /**
1004
+ * Combines three Options using a mapping function.
1005
+ * Only applies the mapper if all three Options contain values.
1006
+ *
1007
+ * @param first - First Option to combine
1008
+ * @param second - Second Option to combine
1009
+ * @param third - Third Option to combine
1010
+ * @param mapper - Function that combines all three values
1011
+ * @returns Option containing the combined result, or None if any Option is None
1012
+ *
1013
+ * @example
1014
+ * ```typescript
1015
+ * map3(some(15), some(6), some(2023), (day, month, year) => `${day}/${month}/${year}`)
1016
+ * // Some("15/6/2023")
1017
+ * ```
1018
+ */
1019
+ declare function map3<A, B, C, D>(first: Option$1<A>, second: Option$1<B>, third: Option$1<C>, mapper: (first: A, second: B, third: C) => D): Option$1<D>;
1020
+ /**
1021
+ * Combines three Eithers using a mapping function.
1022
+ * Returns the mapped result if all Eithers are Right, otherwise the first Left.
1023
+ *
1024
+ * @param first - First Either to combine
1025
+ * @param second - Second Either to combine
1026
+ * @param third - Third Either to combine
1027
+ * @param mapper - Function to combine all three Right values
1028
+ * @returns Either containing the combined result, or the first Left
1029
+ *
1030
+ * @example
1031
+ * ```typescript
1032
+ * map3(right(1), right(2), right(3), (a, b, c) => a + b + c)
1033
+ * // Right(6)
1034
+ * ```
1035
+ */
1036
+ declare function map3<EA, A, EB, B, EC, C, D>(first: Either$1<EA, A>, second: Either$1<EB, B>, third: Either$1<EC, C>, mapper: (first: A, second: B, third: C) => D): Either$1<EA | EB | EC, D>;
1037
+ /**
1038
+ * Combines three Validations using a mapping function.
1039
+ * If all are Valid, applies the mapper. If any are Invalid, accumulates all errors.
1040
+ *
1041
+ * @param first - First Validation to combine
1042
+ * @param second - Second Validation to combine
1043
+ * @param third - Third Validation to combine
1044
+ * @param mapper - Function to combine all three valid values
1045
+ * @returns Validation containing the combined result, or all accumulated errors
1046
+ *
1047
+ * @example
1048
+ * ```typescript
1049
+ * map3(valid(1), valid(2), valid(3), (a, b, c) => a + b + c)
1050
+ * // Valid(6)
1051
+ * ```
1052
+ */
1053
+ declare function map3<EA, A, EB, B, EC, C, D>(first: Validation$1<EA, A>, second: Validation$1<EB, B>, third: Validation$1<EC, C>, mapper: (first: A, second: B, third: C) => D): Validation$1<EA | EB | EC, D>;
1054
+ /**
1055
+ * Combines three Tasks using a mapping function.
1056
+ * Runs all three Tasks and maps their resolved values.
1057
+ *
1058
+ * @param first - First Task to combine
1059
+ * @param second - Second Task to combine
1060
+ * @param third - Third Task to combine
1061
+ * @param mapper - Function that combines all three resolved values
1062
+ * @returns Task containing the combined result
1063
+ */
1064
+ declare function map3<A, B, C, D>(first: Task$1<A>, second: Task$1<B>, third: Task$1<C>, mapper: (first: A, second: B, third: C) => D): Task$1<D>;
1065
+ /**
1066
+ * Combines three TaskEithers using a mapping function.
1067
+ * Returns the mapped result if all resolve to Right, otherwise the first Left.
1068
+ *
1069
+ * @param first - First TaskEither to combine
1070
+ * @param second - Second TaskEither to combine
1071
+ * @param third - Third TaskEither to combine
1072
+ * @param mapper - Function to combine all three Right values
1073
+ * @returns TaskEither containing the combined result, or the first Left
1074
+ */
1075
+ declare function map3<EA, A, EB, B, EC, C, D>(first: TaskEither$1<EA, A>, second: TaskEither$1<EB, B>, third: TaskEither$1<EC, C>, mapper: (first: A, second: B, third: C) => D): TaskEither$1<EA | EB | EC, D>;
1076
+ //#endregion
1077
+ //#region src/option/constructors.d.ts
1078
+ /**
1079
+ * Creates an {@link Option} that contains a value.
1080
+ *
1081
+ * Use this to wrap an existing value into an `Option<T>` representing presence
1082
+ * (as opposed to `none`, which represents absence).
1083
+ *
1084
+ * @typeParam T - Type of the wrapped value.
1085
+ * @param some - The value to store in the option.
1086
+ * @returns An {@link Option} containing the provided value.
1087
+ */
1088
+ declare function some<T>(some: T): Option$1<T>;
1089
+ /**
1090
+ * Creates an {@link Option} representing the absence of a value.
1091
+ *
1092
+ * @typeParam T - The type of the value that would be contained if present.
1093
+ * @returns An {@link Option} in the `None` state.
1094
+ *
1095
+ * @example
1096
+ * ```ts
1097
+ * const value = none<number>();
1098
+ * ```
1099
+ */
1100
+ declare function none<T>(): Option$1<T>;
1101
+ /**
1102
+ * Creates an {@link Option} from a nullable value.
1103
+ *
1104
+ * If {@link nullable} is `null` or `undefined`, returns {@link none}.
1105
+ * Otherwise, wraps the provided value in {@link some}.
1106
+ *
1107
+ * @example
1108
+ * fromNullable(0).getOrElse(() => 123); // 0
1109
+ * fromNullable(null).toNullable(); // null
1110
+ *
1111
+ * @typeParam T - The non-null value type to wrap.
1112
+ * @param nullable - A value that may be `null` or `undefined`.
1113
+ * @returns An {@link Option} that is `Some` when the value is present, otherwise `None`.
1114
+ */
1115
+ declare function fromNullable<T>(nullable: null | undefined | T): Option$1<T>;
1116
+ /**
1117
+ * Creates an {@link Option} from an {@link Either} by extracting the Right value.
1118
+ *
1119
+ * If the Either is Right, returns Some containing the Right value.
1120
+ * If the Either is Left, returns None (discarding the Left value).
1121
+ *
1122
+ * @typeParam L - The type of the Left value (error type) that will be discarded
1123
+ * @typeParam R - The type of the Right value that will be preserved in the Option
1124
+ * @param either - The Either to convert to an Option
1125
+ * @returns Some containing the Right value, or None if the Either was Left
1126
+ *
1127
+ * @example
1128
+ * ```typescript
1129
+ * const success = right(42);
1130
+ * fromEither(success) // Some(42)
1131
+ *
1132
+ * const failure = left("error message");
1133
+ * fromEither(failure) // None
1134
+ * ```
1135
+ */
1136
+ declare function fromEither$2<L, R>(either: Either$1<L, R>): Option$1<R>;
1137
+ //#endregion
1138
+ //#region src/option/helpers.d.ts
1139
+ /**
1140
+ * Converts an array of Options into an Option of array.
1141
+ * If all Options in the array contain values, returns Some containing an array of all values.
1142
+ * If any Option in the array is None, returns None.
1143
+ *
1144
+ * @param opts - Array of Options to sequence
1145
+ * @returns Some containing array of all values if all Options are Some, otherwise None
1146
+ *
1147
+ * @example
1148
+ * ```typescript
1149
+ * sequence([some(1), some(2), some(3)]) // Some([1, 2, 3])
1150
+ * sequence([some(1), none(), some(3)]) // None
1151
+ * ```
1152
+ */
1153
+ declare function sequence$1<T>(opts: Option$1<T>[]): Option$1<T[]>;
1154
+ //#endregion
1155
+ //#region src/option/index.d.ts
1156
+ declare const Option: {
1157
+ fromNullable: typeof fromNullable;
1158
+ fromEither: typeof fromEither$2;
1159
+ sequence: typeof sequence$1;
1160
+ };
1161
+ type Option<T> = Option$1<T>;
1162
+ //#endregion
1163
+ //#region src/task/constructors.d.ts
1164
+ /**
1165
+ * Creates a Task that immediately resolves with the provided value.
1166
+ *
1167
+ * @typeParam T - The type of the value
1168
+ * @param value - The value to wrap in a Task
1169
+ * @returns Task that resolves with the given value
1170
+ *
1171
+ * @example
1172
+ * ```typescript
1173
+ * const t = task(42); // Task<number>
1174
+ * await t.run(); // 42
1175
+ * ```
1176
+ */
1177
+ declare function task<T>(value: T): Task$1<T>;
1178
+ /**
1179
+ * Creates a Task from a lazy Promise-returning thunk.
1180
+ * The thunk is not called until `run()` is invoked.
1181
+ *
1182
+ * @typeParam T - The type of the resolved value
1183
+ * @param thunk - A function that returns a Promise
1184
+ * @returns Task wrapping the lazy Promise
1185
+ *
1186
+ * @example
1187
+ * ```typescript
1188
+ * const fetchUser = fromPromise(() => fetch("/api/user").then(r => r.json()));
1189
+ * await fetchUser.run(); // fetches the user
1190
+ * ```
1191
+ */
1192
+ declare function fromPromise<T>(thunk: () => Promise<T>): Task$1<T>;
1193
+ //#endregion
1194
+ //#region src/task/helpers.d.ts
1195
+ /**
1196
+ * Runs all Tasks concurrently and collects their results into an array.
1197
+ * Equivalent to `Promise.all` for Tasks.
1198
+ *
1199
+ * @param tasks - Array of Tasks to run concurrently
1200
+ * @returns Task that resolves with an array of all results
1201
+ *
1202
+ * @example
1203
+ * ```typescript
1204
+ * await allTasks([task(1), task(2), task(3)]).run() // [1, 2, 3]
1205
+ * ```
1206
+ */
1207
+ declare function allTasks<T>(tasks: Task$1<T>[]): Task$1<T[]>;
1208
+ //#endregion
1209
+ //#region src/task/index.d.ts
1210
+ declare const Task: {
1211
+ fromPromise: typeof fromPromise;
1212
+ all: typeof allTasks;
1213
+ };
1214
+ type Task<T> = Task$1<T>;
1215
+ //#endregion
1216
+ //#region src/taskEither/constructors.d.ts
1217
+ declare function taskRight<T, E = never>(value: T): TaskEither$1<E, T>;
1218
+ declare function taskLeft<E, T = never>(error: E): TaskEither$1<E, T>;
1219
+ declare function fromEither$1<E, T>(either: Either$1<E, T>): TaskEither$1<E, T>;
1220
+ declare function fromTask<T, E = never>(t: Task$1<T>): TaskEither$1<E, T>;
1221
+ declare function tryCatch<T, E>(thunk: () => Promise<T>, onThrow: (err: unknown) => E): TaskEither$1<E, T>;
1222
+ //#endregion
1223
+ //#region src/taskEither/helpers.d.ts
1224
+ /**
1225
+ * Runs all TaskEithers concurrently and collects their Right values into an array.
1226
+ * Short-circuits on the first Left, returning it immediately.
1227
+ * Equivalent to `Promise.all` for TaskEithers.
1228
+ *
1229
+ * @param taskEithers - Array of TaskEithers to run concurrently
1230
+ * @returns TaskEither that resolves with an array of all Right values, or the first Left
1231
+ *
1232
+ * @example
1233
+ * ```typescript
1234
+ * await allTaskEithers([taskRight(1), taskRight(2), taskRight(3)]).run() // Right([1, 2, 3])
1235
+ * await allTaskEithers([taskRight(1), taskLeft("err"), taskRight(3)]).run() // Left("err")
1236
+ * ```
1237
+ */
1238
+ declare function allTaskEithers<E, T>(taskEithers: TaskEither$1<E, T>[]): TaskEither$1<E, T[]>;
1239
+ //#endregion
1240
+ //#region src/taskEither/index.d.ts
1241
+ declare const TaskEither: {
1242
+ fromEither: typeof fromEither$1;
1243
+ fromTask: typeof fromTask;
1244
+ tryCatch: typeof tryCatch;
1245
+ all: typeof allTaskEithers;
1246
+ };
1247
+ type TaskEither<E, T> = TaskEither$1<E, T>;
1248
+ //#endregion
1249
+ //#region src/validation/constructors.d.ts
1250
+ /**
1251
+ * Creates a Validation containing a valid value.
1252
+ *
1253
+ * @param value - The valid value to wrap
1254
+ * @returns Validation containing the valid value
1255
+ *
1256
+ * @example
1257
+ * ```typescript
1258
+ * const v = valid(42); // Validation<never, number>
1259
+ * ```
1260
+ */
1261
+ declare function valid<T, E = never>(value: T): Validation$1<E, T>;
1262
+ /**
1263
+ * Creates a Validation containing a single error.
1264
+ *
1265
+ * @param error - The error to wrap
1266
+ * @returns Validation containing the error
1267
+ *
1268
+ * @example
1269
+ * ```typescript
1270
+ * const v = invalid("Something went wrong"); // Validation<string, never>
1271
+ * ```
1272
+ */
1273
+ declare function invalid<E, T = never>(error: E): Validation$1<E, T>;
1274
+ /**
1275
+ * Creates a Validation from an Either.
1276
+ * Right values become Valid, Left values become Invalid (with a single error).
1277
+ *
1278
+ * @param either - The Either to convert
1279
+ * @returns Validation equivalent of the Either
1280
+ *
1281
+ * @example
1282
+ * ```typescript
1283
+ * fromEither(right(42)) // Valid(42)
1284
+ * fromEither(left("error")) // Invalid(["error"])
1285
+ * ```
1286
+ */
1287
+ declare function fromEither<E, T>(either: Either$1<E, T>): Validation$1<E, T>;
1288
+ /**
1289
+ * Creates a Validation from an Option.
1290
+ * Some values become Valid, None becomes Invalid with the provided error.
1291
+ *
1292
+ * @param opt - The Option to convert
1293
+ * @param onNone - Function that provides the error when Option is None
1294
+ * @returns Validation equivalent of the Option
1295
+ *
1296
+ * @example
1297
+ * ```typescript
1298
+ * fromOption(some(42), () => "missing") // Valid(42)
1299
+ * fromOption(none(), () => "missing") // Invalid(["missing"])
1300
+ * ```
1301
+ */
1302
+ declare function fromOption<E, T>(opt: Option$1<T>, onNone: () => E): Validation$1<E, T>;
1303
+ //#endregion
1304
+ //#region src/validation/helpers.d.ts
1305
+ /**
1306
+ * Converts an array of Validations into a Validation of array.
1307
+ * Returns Valid with all values if all Validations are Valid, otherwise accumulates all errors.
1308
+ *
1309
+ * @param validations - Array of Validations to sequence
1310
+ * @returns Validation containing array of all values, or all accumulated errors
1311
+ *
1312
+ * @example
1313
+ * ```typescript
1314
+ * sequence([valid(1), valid(2), valid(3)]) // Valid([1, 2, 3])
1315
+ * sequence([valid(1), invalid("e1"), invalid("e2")]) // Invalid(["e1", "e2"])
1316
+ * ```
1317
+ */
1318
+ declare function sequence<E, T>(validations: readonly Validation$1<E, T>[]): Validation$1<E, T[]>;
1319
+ //#endregion
1320
+ //#region src/validation/index.d.ts
1321
+ declare const Validation: {
1322
+ fromEither: typeof fromEither;
1323
+ fromOption: typeof fromOption;
1324
+ sequence: typeof sequence;
1325
+ };
1326
+ type Validation<E, T> = Validation$1<E, T>;
1327
+ //#endregion
1328
+ export { Either, type EitherResult, type EitherValue, type Invalid, type Left, NONE, type None, Option, type OptionValue, type Right, type Some, Task, TaskEither, type TaskEitherValue, type TaskValue, type Valid, Validation, type ValidationResult, type ValidationValue, allTaskEithers, allTasks, invalid, left, map2, map3, none, right, some, task, taskLeft, taskRight, valid };