@nlozgachev/pipelined 0.44.0 → 0.45.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,4 +1,4 @@
1
- import { g as WithKind, n as WithValue, d as WithError, T as Thenable, D as Deferred, N as NonEmptyArr, e as WithErrors } from './InternalTypes-BL23H8Qr.mjs';
1
+ import { h as WithKind, o as WithValue, e as WithError, T as Thenable, D as Deferred, a as NonEmptyArr, f as WithErrors } from './InternalTypes-CLE7qlOc.mjs';
2
2
  import { Duration } from './types.mjs';
3
3
 
4
4
  /**
@@ -96,7 +96,7 @@ type None = WithKind<"None">;
96
96
  *
97
97
  * @example
98
98
  * ```ts
99
- * const user = { name: "Alice", email: Maybe.some("alice@example.com") };
99
+ * const user = { name: "Alice", email: Maybe.make.some("alice@example.com") };
100
100
  *
101
101
  * pipe(
102
102
  * user.email,
@@ -107,91 +107,99 @@ type None = WithKind<"None">;
107
107
  */
108
108
  type Maybe<T> = Some<T> | None;
109
109
  declare namespace Maybe {
110
- /**
111
- * Creates a Some containing the given value.
112
- */
113
- const some: <A>(value: A) => Some<A>;
114
- /**
115
- * Type guard that checks if a Maybe is Some.
116
- */
117
- const isSome: <A>(data: Maybe<A>) => data is Some<A>;
118
- /**
119
- * Creates a None (empty Maybe).
120
- */
121
- const none: () => None;
122
- /**
123
- * Type guard that checks if a Maybe is None.
124
- */
125
- const isNone: <A>(data: Maybe<A>) => data is None;
126
- /**
127
- * Creates a Maybe from a nullable value.
128
- * Returns None if the value is null or undefined, Some otherwise.
129
- *
130
- * @example
131
- * ```ts
132
- * Maybe.fromNullable(null); // None
133
- * Maybe.fromNullable(42); // Some(42)
134
- * ```
135
- */
136
- const fromNullable: <A>(value: A | null | undefined) => Maybe<A>;
137
- /**
138
- * Extracts the value from a Maybe, returning null if None.
139
- */
140
- const toNullable: <A>(data: Maybe<A>) => A | null;
141
- /**
142
- * Extracts the value from a Maybe, returning undefined if None.
143
- */
144
- const toUndefined: <A>(data: Maybe<A>) => A | undefined;
145
- /**
146
- * Creates a Maybe from a predicate applied to a value.
147
- * Returns Some if the predicate passes, None otherwise.
148
- *
149
- * @example
150
- * ```ts
151
- * Maybe.fromPredicate((n: number) => n >= 18)(21); // Some(21)
152
- * Maybe.fromPredicate((n: number) => n >= 18)(15); // None
153
- *
154
- * pipe("hello", Maybe.fromPredicate((s: string) => s.length > 0)); // Some("hello")
155
- * pipe("", Maybe.fromPredicate((s: string) => s.length > 0)); // None
156
- * ```
157
- */
158
- const fromPredicate: <A>(pred: (a: A) => boolean) => (a: A) => Maybe<A>;
159
- /**
160
- * Converts a Maybe to a Result.
161
- * Some becomes Ok, None becomes Err with the provided error.
162
- *
163
- * @example
164
- * ```ts
165
- * pipe(
166
- * Maybe.some(42),
167
- * Maybe.toResult(() => "Value was missing")
168
- * ); // Ok(42)
169
- *
170
- * pipe(
171
- * Maybe.none(),
172
- * Maybe.toResult(() => "Value was missing")
173
- * ); // Err("Value was missing")
174
- * ```
175
- */
176
- const toResult: <E>(onNone: () => E) => <A>(data: Maybe<A>) => Result<E, A>;
177
- /**
178
- * Creates a Maybe from a Result.
179
- * Ok becomes Some, Err becomes None (the error is discarded).
180
- *
181
- * @example
182
- * ```ts
183
- * Maybe.fromResult(Result.ok(42)); // Some(42)
184
- * Maybe.fromResult(Result.err("oops")); // None
185
- * ```
186
- */
187
- const fromResult: <E, A>(data: Result<E, A>) => Maybe<A>;
110
+ namespace make {
111
+ /**
112
+ * Creates a Some containing the given value.
113
+ */
114
+ const some: <A>(value: A) => Some<A>;
115
+ /**
116
+ * Creates a None (empty Maybe).
117
+ */
118
+ const none: () => None;
119
+ }
120
+ namespace is {
121
+ /**
122
+ * Type guard that checks if a Maybe is Some.
123
+ */
124
+ const some: <A>(data: Maybe<A>) => data is Some<A>;
125
+ /**
126
+ * Type guard that checks if a Maybe is None.
127
+ */
128
+ const none: <A>(data: Maybe<A>) => data is None;
129
+ }
130
+ namespace to {
131
+ /**
132
+ * Extracts the value from a Maybe, returning null if None.
133
+ */
134
+ const nullable: <A>(data: Maybe<A>) => A | null;
135
+ /**
136
+ * Extracts the value from a Maybe, returning undefined if None.
137
+ */
138
+ const undefined: <A>(data: Maybe<A>) => A | undefined;
139
+ /**
140
+ * Converts a Maybe to a Result.
141
+ * Some becomes Ok, None becomes Err with the provided error.
142
+ *
143
+ * @example
144
+ * ```ts
145
+ * pipe(
146
+ * Maybe.make.some(42),
147
+ * Maybe.to.Result(() => "Value was missing")
148
+ * ); // Ok(42)
149
+ *
150
+ * pipe(
151
+ * Maybe.make.none(),
152
+ * Maybe.to.Result(() => "Value was missing")
153
+ * ); // Err("Value was missing")
154
+ * ```
155
+ */
156
+ const Result: <E>(onNone: () => E) => <A>(data: Maybe<A>) => Result<E, A>;
157
+ }
158
+ namespace from {
159
+ /**
160
+ * Creates a Maybe from a nullable value.
161
+ * Returns None if the value is null or undefined, Some otherwise.
162
+ *
163
+ * @example
164
+ * ```ts
165
+ * Maybe.from.nullable(null); // None
166
+ * Maybe.from.nullable(42); // Some(42)
167
+ * ```
168
+ */
169
+ const nullable: <A>(value: A | null | undefined) => Maybe<A>;
170
+ /**
171
+ * Creates a Maybe from a predicate applied to a value.
172
+ * Returns Some if the predicate passes, None otherwise.
173
+ *
174
+ * @example
175
+ * ```ts
176
+ * Maybe.from.Predicate((n: number) => n >= 18)(21); // Some(21)
177
+ * Maybe.from.Predicate((n: number) => n >= 18)(15); // None
178
+ *
179
+ * pipe("hello", Maybe.from.Predicate((s: string) => s.length > 0)); // Some("hello")
180
+ * pipe("", Maybe.from.Predicate((s: string) => s.length > 0)); // None
181
+ * ```
182
+ */
183
+ const Predicate: <A>(pred: (a: A) => boolean) => (a: A) => Maybe<A>;
184
+ /**
185
+ * Creates a Maybe from a Result.
186
+ * Ok becomes Some, Err becomes None (the error is discarded).
187
+ *
188
+ * @example
189
+ * ```ts
190
+ * Maybe.from.Result(Result.make.ok(42)); // Some(42)
191
+ * Maybe.from.Result(Result.make.err("oops")); // None
192
+ * ```
193
+ */
194
+ const Result: <E, A>(data: Result<E, A>) => Maybe<A>;
195
+ }
188
196
  /**
189
197
  * Transforms the value inside a Maybe if it exists.
190
198
  *
191
199
  * @example
192
200
  * ```ts
193
- * pipe(Maybe.some(5), Maybe.map(n => n * 2)); // Some(10)
194
- * pipe(Maybe.none(), Maybe.map(n => n * 2)); // None
201
+ * pipe(Maybe.make.some(5), Maybe.map(n => n * 2)); // Some(10)
202
+ * pipe(Maybe.make.none(), Maybe.map(n => n * 2)); // None
195
203
  * ```
196
204
  */
197
205
  const map: <A, B>(f: (a: A) => B) => (data: Maybe<A>) => Maybe<B>;
@@ -203,11 +211,11 @@ declare namespace Maybe {
203
211
  * ```ts
204
212
  * const parseNumber = (s: string): Maybe<number> => {
205
213
  * const n = parseInt(s, 10);
206
- * return isNaN(n) ? Maybe.none() : Maybe.some(n);
214
+ * return isNaN(n) ? Maybe.make.none() : Maybe.make.some(n);
207
215
  * };
208
216
  *
209
- * pipe(Maybe.some("42"), Maybe.chain(parseNumber)); // Some(42)
210
- * pipe(Maybe.some("abc"), Maybe.chain(parseNumber)); // None
217
+ * pipe(Maybe.make.some("42"), Maybe.chain(parseNumber)); // Some(42)
218
+ * pipe(Maybe.make.some("abc"), Maybe.chain(parseNumber)); // None
211
219
  * ```
212
220
  */
213
221
  const chain: <A, B>(f: (a: A) => Maybe<B>) => (data: Maybe<A>) => Maybe<B>;
@@ -217,7 +225,7 @@ declare namespace Maybe {
217
225
  * @example
218
226
  * ```ts
219
227
  * pipe(
220
- * Maybe.some(5),
228
+ * Maybe.make.some(5),
221
229
  * Maybe.fold(
222
230
  * () => "No value",
223
231
  * n => `Value: ${n}`
@@ -251,9 +259,9 @@ declare namespace Maybe {
251
259
  *
252
260
  * @example
253
261
  * ```ts
254
- * pipe(Maybe.some(5), Maybe.getOrElse(() => 0)); // 5
255
- * pipe(Maybe.none(), Maybe.getOrElse(() => 0)); // 0
256
- * pipe(Maybe.none<string>(), Maybe.getOrElse(() => null)); // null — typed as string | null
262
+ * pipe(Maybe.make.some(5), Maybe.getOrElse(() => 0)); // 5
263
+ * pipe(Maybe.make.none(), Maybe.getOrElse(() => 0)); // 0
264
+ * pipe(Maybe.make.none<string>(), Maybe.getOrElse(() => null)); // null — typed as string | null
257
265
  * ```
258
266
  */
259
267
  const getOrElse: <A, B>(defaultValue: () => B) => (data: Maybe<A>) => A | B;
@@ -264,7 +272,7 @@ declare namespace Maybe {
264
272
  * @example
265
273
  * ```ts
266
274
  * pipe(
267
- * Maybe.some(5),
275
+ * Maybe.make.some(5),
268
276
  * Maybe.tap(n => console.log("Value:", n)),
269
277
  * Maybe.map(n => n * 2)
270
278
  * );
@@ -277,8 +285,8 @@ declare namespace Maybe {
277
285
  *
278
286
  * @example
279
287
  * ```ts
280
- * pipe(Maybe.some(5), Maybe.filter(n => n > 3)); // Some(5)
281
- * pipe(Maybe.some(2), Maybe.filter(n => n > 3)); // None
288
+ * pipe(Maybe.make.some(5), Maybe.filter(n => n > 3)); // Some(5)
289
+ * pipe(Maybe.make.some(2), Maybe.filter(n => n > 3)); // None
282
290
  * ```
283
291
  */
284
292
  const filter: <A>(predicate: (a: A) => boolean) => (data: Maybe<A>) => Maybe<A>;
@@ -294,9 +302,9 @@ declare namespace Maybe {
294
302
  * ```ts
295
303
  * const add = (a: number) => (b: number) => a + b;
296
304
  * pipe(
297
- * Maybe.some(add),
298
- * Maybe.ap(Maybe.some(5)),
299
- * Maybe.ap(Maybe.some(3))
305
+ * Maybe.make.some(add),
306
+ * Maybe.ap(Maybe.make.some(5)),
307
+ * Maybe.ap(Maybe.make.some(3))
300
308
  * ); // Some(8)
301
309
  * ```
302
310
  */
@@ -307,7 +315,7 @@ declare namespace Maybe {
307
315
  *
308
316
  * @example
309
317
  * ```ts
310
- * pipe(Maybe.some(42), Maybe.bindTo("value")); // Some({ value: 42 })
318
+ * pipe(Maybe.make.some(42), Maybe.bindTo("value")); // Some({ value: 42 })
311
319
  * ```
312
320
  */
313
321
  const bindTo: <K extends string>(key: K) => <A>(data: Maybe<A>) => Maybe<{ [P in K]: A; }>;
@@ -317,8 +325,8 @@ declare namespace Maybe {
317
325
  * @example
318
326
  * ```ts
319
327
  * pipe(
320
- * Maybe.some({ a: 1 }),
321
- * Maybe.bind("b", ({ a }) => Maybe.some(a + 1))
328
+ * Maybe.make.some({ a: 1 }),
329
+ * Maybe.bind("b", ({ a }) => Maybe.make.some(a + 1))
322
330
  * ); // Some({ a: 1, b: 2 })
323
331
  * ```
324
332
  */
@@ -330,8 +338,8 @@ declare namespace Maybe {
330
338
  * @example
331
339
  * ```ts
332
340
  * Maybe.struct({
333
- * name: Maybe.some("Alice"),
334
- * age: Maybe.some(30)
341
+ * name: Maybe.make.some("Alice"),
342
+ * age: Maybe.make.some(30)
335
343
  * }); // Some({ name: "Alice", age: 30 })
336
344
  * ```
337
345
  */
@@ -425,7 +433,7 @@ type Err<E> = WithKind<"Err"> & WithError<E>;
425
433
  * @example
426
434
  * ```ts
427
435
  * const divide = (a: number, b: number): Result<string, number> =>
428
- * b === 0 ? Result.err("Division by zero") : Result.ok(a / b);
436
+ * b === 0 ? Result.make.err("Division by zero") : Result.make.ok(a / b);
429
437
  *
430
438
  * pipe(
431
439
  * divide(10, 2),
@@ -436,22 +444,26 @@ type Err<E> = WithKind<"Err"> & WithError<E>;
436
444
  */
437
445
  type Result<E, A> = Ok<A> | Err<E>;
438
446
  declare namespace Result {
439
- /**
440
- * Creates a successful Result with the given value.
441
- */
442
- const ok: <A>(value: A) => Ok<A>;
443
- /**
444
- * Creates a failed Result with the given error.
445
- */
446
- const err: <E>(e: E) => Err<E>;
447
- /**
448
- * Type guard that checks if a Result is Ok.
449
- */
450
- const isOk: <E, A>(data: Result<E, A>) => data is Ok<A>;
451
- /**
452
- * Type guard that checks if a Result is Err.
453
- */
454
- const isErr: <E, A>(data: Result<E, A>) => data is Err<E>;
447
+ namespace make {
448
+ /**
449
+ * Creates a successful Result with the given value.
450
+ */
451
+ const ok: <A>(value: A) => Ok<A>;
452
+ /**
453
+ * Creates a failed Result with the given error.
454
+ */
455
+ const err: <E>(e: E) => Err<E>;
456
+ }
457
+ namespace is {
458
+ /**
459
+ * Type guard that checks if a Result is Ok.
460
+ */
461
+ const ok: <E, A>(data: Result<E, A>) => data is Ok<A>;
462
+ /**
463
+ * Type guard that checks if a Result is Err.
464
+ */
465
+ const err: <E, A>(data: Result<E, A>) => data is Err<E>;
466
+ }
455
467
  /**
456
468
  * Creates a Result from a function that may throw.
457
469
  * Catches any errors and transforms them using the onError function.
@@ -471,8 +483,8 @@ declare namespace Result {
471
483
  *
472
484
  * @example
473
485
  * ```ts
474
- * pipe(Result.ok(5), Result.map(n => n * 2)); // Ok(10)
475
- * pipe(Result.err("error"), Result.map(n => n * 2)); // Err("error")
486
+ * pipe(Result.make.ok(5), Result.map(n => n * 2)); // Ok(10)
487
+ * pipe(Result.make.err("error"), Result.map(n => n * 2)); // Err("error")
476
488
  * ```
477
489
  */
478
490
  const map: <E, A, B>(f: (a: A) => B) => (data: Result<E, A>) => Result<E, B>;
@@ -481,7 +493,7 @@ declare namespace Result {
481
493
  *
482
494
  * @example
483
495
  * ```ts
484
- * pipe(Result.err("oops"), Result.mapError(e => e.toUpperCase())); // Err("OOPS")
496
+ * pipe(Result.make.err("oops"), Result.mapError(e => e.toUpperCase())); // Err("OOPS")
485
497
  * ```
486
498
  */
487
499
  const mapError: <E, F, A>(f: (e: E) => F) => (data: Result<E, A>) => Result<F, A>;
@@ -492,10 +504,10 @@ declare namespace Result {
492
504
  * @example
493
505
  * ```ts
494
506
  * const validatePositive = (n: number): Result<string, number> =>
495
- * n > 0 ? Result.ok(n) : Result.err("Must be positive");
507
+ * n > 0 ? Result.make.ok(n) : Result.make.err("Must be positive");
496
508
  *
497
- * pipe(Result.ok(5), Result.chain(validatePositive)); // Ok(5)
498
- * pipe(Result.ok(-1), Result.chain(validatePositive)); // Err("Must be positive")
509
+ * pipe(Result.make.ok(5), Result.chain(validatePositive)); // Ok(5)
510
+ * pipe(Result.make.ok(-1), Result.chain(validatePositive)); // Err("Must be positive")
499
511
  * ```
500
512
  */
501
513
  const chain: <E, A, B>(f: (a: A) => Result<E, B>) => (data: Result<E, A>) => Result<E, B>;
@@ -505,7 +517,7 @@ declare namespace Result {
505
517
  * @example
506
518
  * ```ts
507
519
  * pipe(
508
- * Result.ok(5),
520
+ * Result.make.ok(5),
509
521
  * Result.fold(
510
522
  * e => `Error: ${e}`,
511
523
  * n => `Value: ${n}`
@@ -539,9 +551,9 @@ declare namespace Result {
539
551
  *
540
552
  * @example
541
553
  * ```ts
542
- * pipe(Result.ok(5), Result.getOrElse(() => 0)); // 5
543
- * pipe(Result.err("error"), Result.getOrElse(() => 0)); // 0
544
- * pipe(Result.err("error"), Result.getOrElse(() => null)); // null — typed as number | null
554
+ * pipe(Result.make.ok(5), Result.getOrElse(() => 0)); // 5
555
+ * pipe(Result.make.err("error"), Result.getOrElse(() => 0)); // 0
556
+ * pipe(Result.make.err("error"), Result.getOrElse(() => null)); // null — typed as number | null
545
557
  * ```
546
558
  */
547
559
  const getOrElse: <E, A, B>(defaultValue: () => B) => (data: Result<E, A>) => A | B;
@@ -552,7 +564,7 @@ declare namespace Result {
552
564
  * @example
553
565
  * ```ts
554
566
  * pipe(
555
- * Result.ok(5),
567
+ * Result.make.ok(5),
556
568
  * Result.tap(n => console.log("Value:", n)),
557
569
  * Result.map(n => n * 2)
558
570
  * );
@@ -566,63 +578,65 @@ declare namespace Result {
566
578
  * @example
567
579
  * ```ts
568
580
  * pipe(
569
- * Result.err("not found"),
581
+ * Result.make.err("not found"),
570
582
  * Result.tapError(e => console.error("validation failed:", e)),
571
583
  * Result.chain(save),
572
584
  * )
573
585
  * ```
574
586
  */
575
587
  const tapError: <E, A>(f: (e: E) => void) => (data: Result<E, A>) => Result<E, A>;
576
- /**
577
- * Creates a Result from a predicate applied to a value.
578
- * Returns Ok if the predicate passes, Err from onFalse otherwise.
579
- *
580
- * @example
581
- * ```ts
582
- * pipe(5, Result.fromPredicate(n => n > 0, n => `${n} is not positive`)); // Ok(5)
583
- * pipe(-1, Result.fromPredicate(n => n > 0, n => `${n} is not positive`)); // Err("-1 is not positive")
584
- * pipe("", Result.fromPredicate(s => s.length > 0, () => "empty string")); // Err("empty string")
585
- * ```
586
- */
587
- const fromPredicate: <E, A>(pred: (a: A) => boolean, onFalse: (a: A) => E) => (a: A) => Result<E, A>;
588
- /**
589
- * Creates a Result from a nullable value.
590
- * Returns Ok if the value is not null or undefined, error from onNull otherwise.
591
- *
592
- * @example
593
- * ```ts
594
- * pipe(null, Result.fromNullable(() => "is null")); // Err("is null")
595
- * pipe(42, Result.fromNullable(() => "is null")); // Ok(42)
596
- * ```
597
- */
598
- const fromNullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => Result<E, A>;
599
- /**
600
- * Creates a Result from a Maybe.
601
- * Some becomes Ok, None becomes error from onNone.
602
- *
603
- * @example
604
- * ```ts
605
- * pipe(Maybe.none(), Result.fromMaybe(() => "is none")); // Err("is none")
606
- * pipe(Maybe.some(42), Result.fromMaybe(() => "is none")); // Ok(42)
607
- * ```
608
- */
609
- const fromMaybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => Result<E, A>;
610
- /**
611
- * Wraps a throwing function of any arguments, returning a new function
612
- * that catches errors and returns a Result.
613
- *
614
- * @example
615
- * ```ts
616
- * const safeParse = Result.fromThrowable(
617
- * (s: string) => JSON.parse(s),
618
- * (e) => new Error(`Parse error: ${e}`)
619
- * );
620
- *
621
- * safeParse('{"a":1}'); // Ok({ a: 1 })
622
- * safeParse('invalid'); // Err(Error)
623
- * ```
624
- */
625
- const fromThrowable: <Args extends readonly unknown[], A, E>(f: (...args: Args) => A, onError: (e: unknown) => E) => (...args: Args) => Result<E, A>;
588
+ namespace from {
589
+ /**
590
+ * Creates a Result from a predicate applied to a value.
591
+ * Returns Ok if the predicate passes, Err from onFalse otherwise.
592
+ *
593
+ * @example
594
+ * ```ts
595
+ * pipe(5, Result.from.Predicate(n => n > 0, n => `${n} is not positive`)); // Ok(5)
596
+ * pipe(-1, Result.from.Predicate(n => n > 0, n => `${n} is not positive`)); // Err("-1 is not positive")
597
+ * pipe("", Result.from.Predicate(s => s.length > 0, () => "empty string")); // Err("empty string")
598
+ * ```
599
+ */
600
+ const Predicate: <E, A>(pred: (a: A) => boolean, onFalse: (a: A) => E) => (a: A) => Result<E, A>;
601
+ /**
602
+ * Creates a Result from a nullable value.
603
+ * Returns Ok if the value is not null or undefined, error from onNull otherwise.
604
+ *
605
+ * @example
606
+ * ```ts
607
+ * pipe(null, Result.from.nullable(() => "is null")); // Err("is null")
608
+ * pipe(42, Result.from.nullable(() => "is null")); // Ok(42)
609
+ * ```
610
+ */
611
+ const nullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => Result<E, A>;
612
+ /**
613
+ * Creates a Result from a Maybe.
614
+ * Some becomes Ok, None becomes error from onNone.
615
+ *
616
+ * @example
617
+ * ```ts
618
+ * pipe(Maybe.make.none(), Result.from.Maybe(() => "is none")); // Err("is none")
619
+ * pipe(Maybe.make.some(42), Result.from.Maybe(() => "is none")); // Ok(42)
620
+ * ```
621
+ */
622
+ const Maybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => Result<E, A>;
623
+ /**
624
+ * Wraps a throwing function of any arguments, returning a new function
625
+ * that catches errors and returns a Result.
626
+ *
627
+ * @example
628
+ * ```ts
629
+ * const safeParse = Result.from.throwable(
630
+ * (s: string) => JSON.parse(s),
631
+ * (e) => new Error(`Parse error: ${e}`)
632
+ * );
633
+ *
634
+ * safeParse('{"a":1}'); // Ok({ a: 1 })
635
+ * safeParse('invalid'); // Err(Error)
636
+ * ```
637
+ */
638
+ const throwable: <Args extends readonly unknown[], A, E>(f: (...args: Args) => A, onError: (e: unknown) => E) => (...args: Args) => Result<E, A>;
639
+ }
626
640
  /**
627
641
  * Recovers from an error by providing a fallback Result.
628
642
  * The fallback can produce a different success type, widening the result to `Result<E, A | B>`.
@@ -635,23 +649,25 @@ declare namespace Result {
635
649
  * @example
636
650
  * ```ts
637
651
  * pipe(
638
- * Result.err(new Error("not found")),
639
- * Result.recoverUnless(e => e.message === "fatal", () => Result.ok(0))
652
+ * Result.make.err(new Error("not found")),
653
+ * Result.recoverUnless(e => e.message === "fatal", () => Result.make.ok(0))
640
654
  * ); // Ok(0)
641
655
  * ```
642
656
  */
643
657
  const recoverUnless: <E, A, B>(isBlocked: (e: E) => boolean, fallback: () => Result<E, B>) => (data: Result<E, A>) => Result<E, A | B>;
644
- /**
645
- * Converts a Result to a Maybe.
646
- * Ok becomes Some, Err becomes None (the error is discarded).
647
- *
648
- * @example
649
- * ```ts
650
- * Result.toMaybe(Result.ok(42)); // Some(42)
651
- * Result.toMaybe(Result.err("oops")); // None
652
- * ```
653
- */
654
- const toMaybe: <E, A>(data: Result<E, A>) => Maybe<A>;
658
+ namespace to {
659
+ /**
660
+ * Converts a Result to a Maybe.
661
+ * Ok becomes Some, Err becomes None (the error is discarded).
662
+ *
663
+ * @example
664
+ * ```ts
665
+ * Result.to.Maybe(Result.make.ok(42)); // Some(42)
666
+ * Result.to.Maybe(Result.make.err("oops")); // None
667
+ * ```
668
+ */
669
+ const Maybe: <E, A>(data: Result<E, A>) => Maybe<A>;
670
+ }
655
671
  /**
656
672
  * Applies a function wrapped in a Result to a value wrapped in a Result.
657
673
  *
@@ -659,9 +675,9 @@ declare namespace Result {
659
675
  * ```ts
660
676
  * const add = (a: number) => (b: number) => a + b;
661
677
  * pipe(
662
- * Result.ok(add),
663
- * Result.ap(Result.ok(5)),
664
- * Result.ap(Result.ok(3))
678
+ * Result.make.ok(add),
679
+ * Result.ap(Result.make.ok(5)),
680
+ * Result.ap(Result.make.ok(3))
665
681
  * ); // Ok(8)
666
682
  * ```
667
683
  */
@@ -672,7 +688,7 @@ declare namespace Result {
672
688
  *
673
689
  * @example
674
690
  * ```ts
675
- * pipe(Result.ok(42), Result.bindTo("value")); // Ok({ value: 42 })
691
+ * pipe(Result.make.ok(42), Result.bindTo("value")); // Ok({ value: 42 })
676
692
  * ```
677
693
  */
678
694
  const bindTo: <K extends string>(key: K) => <E, A>(data: Result<E, A>) => Result<E, { [P in K]: A; }>;
@@ -682,8 +698,8 @@ declare namespace Result {
682
698
  * @example
683
699
  * ```ts
684
700
  * pipe(
685
- * Result.ok({ a: 1 }),
686
- * Result.bind("b", ({ a }) => Result.ok(a + 1))
701
+ * Result.make.ok({ a: 1 }),
702
+ * Result.bind("b", ({ a }) => Result.make.ok(a + 1))
687
703
  * ); // Ok({ a: 1, b: 2 })
688
704
  * ```
689
705
  */
@@ -695,8 +711,8 @@ declare namespace Result {
695
711
  * @example
696
712
  * ```ts
697
713
  * Result.struct({
698
- * name: Result.ok("Alice"),
699
- * age: Result.ok(30)
714
+ * name: Result.make.ok("Alice"),
715
+ * age: Result.make.ok(30)
700
716
  * }); // Ok({ name: "Alice", age: 30 })
701
717
  * ```
702
718
  */
@@ -704,19 +720,17 @@ declare namespace Result {
704
720
  }
705
721
 
706
722
  /**
707
- * A Task that resolves to an optional value.
708
- * Combines async operations with the Maybe type for values that may not exist.
723
+ * TaskMaybe represents a lazy, infallible async operation that resolves to a `Maybe<A>`.
724
+ * It is a type alias for `Task<Maybe<A>>`.
725
+ *
726
+ * Use Task.Maybe for async operations that can result in a missing value (e.g. database lookups).
709
727
  *
710
728
  * @example
711
729
  * ```ts
712
730
  * const findUser = (id: string): Task.Maybe<User> =>
713
- * Task.Maybe.tryCatch(() => db.users.findById(id));
714
- *
715
- * pipe(
716
- * findUser("123"),
717
- * Task.Maybe.map(user => user.name),
718
- * Task.Maybe.getOrElse(() => "Unknown")
719
- * )();
731
+ * Task.Maybe.tryCatch((signal) =>
732
+ * fetch(`/users/${id}`, { signal }).then(r => r.ok ? r.json() : null)
733
+ * );
720
734
  * ```
721
735
  */
722
736
  type TaskMaybe<A> = Task<Maybe<A>>;
@@ -729,24 +743,26 @@ declare namespace TaskMaybe {
729
743
  * Creates a Task.Maybe that resolves to None.
730
744
  */
731
745
  const none: <A = never>() => TaskMaybe<A>;
732
- /**
733
- * Lifts an Option into a Task.Maybe.
734
- */
735
- const fromMaybe: <A>(option: Maybe<A>) => TaskMaybe<A>;
736
- /**
737
- * Creates a Task.Maybe from a nullable value.
738
- * Returns Some if the value is not null or undefined, None otherwise.
739
- */
740
- const fromNullable: <A>(value: A | null | undefined) => TaskMaybe<A>;
741
- /**
742
- * Creates a Task.Maybe from a Result.
743
- * Ok becomes Some, Error becomes None (the error value is discarded).
744
- */
745
- const fromResult: <E, A>(result: Result<E, A>) => TaskMaybe<A>;
746
- /**
747
- * Lifts a Task into a Task.Maybe by wrapping its result in Some.
748
- */
749
- const fromTask: <A>(task: Task<A>) => TaskMaybe<A>;
746
+ namespace from {
747
+ /**
748
+ * Lifts an Option into a Task.Maybe.
749
+ */
750
+ const Maybe: <A>(option: Maybe<A>) => TaskMaybe<A>;
751
+ /**
752
+ * Creates a Task.Maybe from a nullable value.
753
+ * Returns Some if the value is not null or undefined, None otherwise.
754
+ */
755
+ const nullable: <A>(value: A | null | undefined) => TaskMaybe<A>;
756
+ /**
757
+ * Creates a Task.Maybe from a Result.
758
+ * Ok becomes Some, Error becomes None (the error value is discarded).
759
+ */
760
+ const Result: <E, A>(result: Result<E, A>) => TaskMaybe<A>;
761
+ /**
762
+ * Lifts a Task into a Task.Maybe by wrapping its result in Some.
763
+ */
764
+ const Task: <A>(task: Task<A>) => TaskMaybe<A>;
765
+ }
750
766
  /**
751
767
  * Creates a Task.Maybe from a Promise-returning function.
752
768
  * Returns Some if the promise resolves, None if it rejects.
@@ -818,18 +834,20 @@ declare namespace TaskMaybe {
818
834
  * Filters the value inside a Task.Maybe. Returns None if the predicate fails.
819
835
  */
820
836
  const filter: <A>(predicate: (a: A) => boolean) => (data: TaskMaybe<A>) => TaskMaybe<A>;
821
- /**
822
- * Converts a Task.Maybe to a Task.Result, using onNone to produce the error value.
823
- *
824
- * @example
825
- * ```ts
826
- * pipe(
827
- * findUser("123"),
828
- * Task.Maybe.toResult(() => "User not found")
829
- * );
830
- * ```
831
- */
832
- const toResult: <E>(onNone: () => E) => <A>(data: TaskMaybe<A>) => Task.Result<E, A>;
837
+ namespace to {
838
+ /**
839
+ * Converts a Task.Maybe to a Task.Result, using onNone to produce the error value.
840
+ *
841
+ * @example
842
+ * ```ts
843
+ * pipe(
844
+ * findUser("123"),
845
+ * Task.Maybe.to.Result(() => "User not found")
846
+ * );
847
+ * ```
848
+ */
849
+ const Result: <E>(onNone: () => E) => <A>(data: TaskMaybe<A>) => Task.Result<E, A>;
850
+ }
833
851
  /**
834
852
  * Lifts a Task.Maybe value into an accumulator object.
835
853
  *
@@ -901,25 +919,27 @@ declare namespace TaskResult {
901
919
  * Creates a failed Task.Result with the given error.
902
920
  */
903
921
  const err: <E, A>(error: E) => TaskResult<E, A>;
904
- /**
905
- * Creates a Task.Result from a nullable value.
906
- * Returns Ok if the value is not null or undefined, err from onNull otherwise.
907
- */
908
- const fromNullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => TaskResult<E, A>;
909
- /**
910
- * Creates a Task.Result from a Maybe.
911
- * Some becomes Ok, None becomes err from onNone.
912
- */
913
- const fromMaybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => TaskResult<E, A>;
914
- /**
915
- * Lifts a Result into a Task.Result.
916
- */
917
- const fromResult: <E, A>(result: Result<E, A>) => TaskResult<E, A>;
918
- /**
919
- * Wraps a Promise-returning function of any arguments, returning a new function
920
- * that catches rejections and returns a Task.Result.
921
- */
922
- const fromThrowable: <Args extends readonly unknown[], A, E>(f: (...args: Args) => Promise<A>, onError: (e: unknown) => E) => (...args: Args) => TaskResult<E, A>;
922
+ namespace from {
923
+ /**
924
+ * Creates a Task.Result from a nullable value.
925
+ * Returns Ok if the value is not null or undefined, err from onNull otherwise.
926
+ */
927
+ const nullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => TaskResult<E, A>;
928
+ /**
929
+ * Creates a Task.Result from a Maybe.
930
+ * Some becomes Ok, None becomes err from onNone.
931
+ */
932
+ const Maybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => TaskResult<E, A>;
933
+ /**
934
+ * Lifts a Result into a Task.Result.
935
+ */
936
+ const Result: <E, A>(result: Result<E, A>) => TaskResult<E, A>;
937
+ /**
938
+ * Wraps a Promise-returning function of any arguments, returning a new function
939
+ * that catches rejections and returns a Task.Result.
940
+ */
941
+ const throwable: <Args extends readonly unknown[], A, E>(f: (...args: Args) => Promise<A>, onError: (e: unknown) => E) => (...args: Args) => TaskResult<E, A>;
942
+ }
923
943
  /**
924
944
  * Creates a Task.Result from a function that may throw.
925
945
  * Catches any errors and transforms them using the onError function.
@@ -1005,7 +1025,7 @@ declare namespace TaskResult {
1005
1025
  * Task.Result.chain(user => fetchPosts(user.id)),
1006
1026
  * Task.Result.run(controller.signal),
1007
1027
  * );
1008
- * if (Result.isOk(result)) render(result.value);
1028
+ * if (Result.is.ok(result)) render(result.value);
1009
1029
  * ```
1010
1030
  */
1011
1031
  const run: (signal?: AbortSignal) => <E, A>(task: TaskResult<E, A>) => Deferred<Result<E, A>>;
@@ -1082,26 +1102,28 @@ declare namespace TaskValidation {
1082
1102
  * Creates a failed Task.Validation from multiple errors.
1083
1103
  */
1084
1104
  const failedAll: <E, A>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
1085
- /**
1086
- * Lifts a Validation into a Task.Validation.
1087
- */
1088
- const fromValidation: <E, A>(validation: Validation<E, A>) => TaskValidation<E, A>;
1089
- /**
1090
- * Creates a Task.Validation from a nullable value.
1091
- * If the value is null or undefined, returns Failed with the error from onNull.
1092
- * Otherwise, returns Passed.
1093
- */
1094
- const fromNullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => TaskValidation<E, A>;
1095
- /**
1096
- * Creates a Task.Validation from a Maybe.
1097
- * Some becomes Passed, None becomes Failed with the error from onNone.
1098
- */
1099
- const fromMaybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => TaskValidation<E, A>;
1100
- /**
1101
- * Creates a Task.Validation from a Result.
1102
- * Ok becomes Passed, Err(e) becomes Failed([e]).
1103
- */
1104
- const fromResult: <E, A>(result: Result<E, A>) => TaskValidation<E, A>;
1105
+ namespace from {
1106
+ /**
1107
+ * Lifts a Validation into a Task.Validation.
1108
+ */
1109
+ const Validation: <E, A>(validation: Validation<E, A>) => TaskValidation<E, A>;
1110
+ /**
1111
+ * Creates a Task.Validation from a nullable value.
1112
+ * If the value is null or undefined, returns Failed with the error from onNull.
1113
+ * Otherwise, returns Passed.
1114
+ */
1115
+ const nullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => TaskValidation<E, A>;
1116
+ /**
1117
+ * Creates a Task.Validation from a Maybe.
1118
+ * Some becomes Passed, None becomes Failed with the error from onNone.
1119
+ */
1120
+ const Maybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => TaskValidation<E, A>;
1121
+ /**
1122
+ * Creates a Task.Validation from a Result.
1123
+ * Ok becomes Passed, Err(e) becomes Failed([e]).
1124
+ */
1125
+ const Result: <E, A>(result: Result<E, A>) => TaskValidation<E, A>;
1126
+ }
1105
1127
  /**
1106
1128
  * Creates a Task.Validation from a Promise-returning function.
1107
1129
  * Catches any errors and transforms them using the onError function.
@@ -1265,9 +1287,9 @@ declare namespace TaskValidation {
1265
1287
  * ```
1266
1288
  *
1267
1289
  * When you need an explicit `Promise<A>` (e.g. for a third-party API), convert
1268
- * the `Deferred` with `Deferred.toPromise`:
1290
+ * the `Deferred` with `Deferred.to.Promise`:
1269
1291
  * ```ts
1270
- * const p: Promise<number> = Deferred.toPromise(task());
1292
+ * const p: Promise<number> = Deferred.to.Promise(task());
1271
1293
  * ```
1272
1294
  *
1273
1295
  * @example
@@ -1296,27 +1318,29 @@ declare namespace Task {
1296
1318
  * ```
1297
1319
  */
1298
1320
  const resolve: <A>(value: A) => Task<A>;
1299
- /**
1300
- * Creates a Task from a function that returns a Promise.
1301
- * The factory optionally receives an `AbortSignal` forwarded from the call site.
1302
- *
1303
- * @example
1304
- * ```ts
1305
- * const getTimestamp = Task.from(() => Promise.resolve(Date.now()));
1306
- * ```
1307
- */
1308
- const from: <A>(f: (signal?: AbortSignal) => Thenable<A>) => Task<A>;
1309
- /**
1310
- * Creates a Task from a lazy synchronous thunk.
1311
- * Unlike `Task.resolve(f())`, `fromSync` does not evaluate `f` until the Task is called.
1312
- *
1313
- * @example
1314
- * ```ts
1315
- * const t = Task.fromSync(() => Date.now()); // Date.now() not called yet
1316
- * const ts = await t(); // called here, every time
1317
- * ```
1318
- */
1319
- const fromSync: <A>(f: () => A) => Task<A>;
1321
+ namespace from {
1322
+ /**
1323
+ * Creates a Task from a function that returns a Promise.
1324
+ * The factory optionally receives an `AbortSignal` forwarded from the call site.
1325
+ *
1326
+ * @example
1327
+ * ```ts
1328
+ * const getTimestamp = Task.from.Promise(() => Promise.resolve(Date.now()));
1329
+ * ```
1330
+ */
1331
+ const Promise: <A>(f: (signal?: AbortSignal) => Thenable<A>) => Task<A>;
1332
+ /**
1333
+ * Creates a Task from a lazy synchronous thunk.
1334
+ * Unlike `Task.resolve(f())`, `from.sync` does not evaluate `f` until the Task is called.
1335
+ *
1336
+ * @example
1337
+ * ```ts
1338
+ * const t = Task.from.sync(() => Date.now()); // Date.now() not called yet
1339
+ * const ts = await t(); // called here, every time
1340
+ * ```
1341
+ */
1342
+ const sync: <A>(f: () => A) => Task<A>;
1343
+ }
1320
1344
  /**
1321
1345
  * Transforms the value inside a Task.
1322
1346
  *
@@ -1439,8 +1463,8 @@ declare namespace Task {
1439
1463
  *
1440
1464
  * @example
1441
1465
  * ```ts
1442
- * const fast = Task.from(() => new Promise<string>(r => setTimeout(() => r("fast"), 10)));
1443
- * const slow = Task.from(() => new Promise<string>(r => setTimeout(() => r("slow"), 200)));
1466
+ * const fast = Task.from.Promise(() => new Promise<string>(r => setTimeout(() => r("fast"), 10)));
1467
+ * const slow = Task.from.Promise(() => new Promise<string>(r => setTimeout(() => r("slow"), 200)));
1444
1468
  *
1445
1469
  * await Task.race([fast, slow])(); // "fast"
1446
1470
  * ```
@@ -1464,7 +1488,7 @@ declare namespace Task {
1464
1488
  * @example
1465
1489
  * ```ts
1466
1490
  * let log: number[] = [];
1467
- * const makeTask = (n: number) => Task.from(() => {
1491
+ * const makeTask = (n: number) => Task.from.Promise(() => {
1468
1492
  * log.push(n);
1469
1493
  * return Promise.resolve(n);
1470
1494
  * });
@@ -1571,14 +1595,14 @@ type Failed<E> = WithKind<"Failed"> & WithErrors<E>;
1571
1595
  * @example
1572
1596
  * ```ts
1573
1597
  * const validateName = (name: string): Validation<string, string> =>
1574
- * name.length > 0 ? Validation.passed(name) : Validation.failed("Name is required");
1598
+ * name.length > 0 ? Validation.make.passed(name) : Validation.make.failed("Name is required");
1575
1599
  *
1576
1600
  * const validateAge = (age: number): Validation<string, number> =>
1577
- * age >= 0 ? Validation.passed(age) : Validation.failed("Age must be positive");
1601
+ * age >= 0 ? Validation.make.passed(age) : Validation.make.failed("Age must be positive");
1578
1602
  *
1579
1603
  * // Accumulates all errors using ap
1580
1604
  * pipe(
1581
- * Validation.passed((name: string) => (age: number) => ({ name, age })),
1605
+ * Validation.make.passed((name: string) => (age: number) => ({ name, age })),
1582
1606
  * Validation.ap(validateName("")),
1583
1607
  * Validation.ap(validateAge(-1))
1584
1608
  * );
@@ -1587,88 +1611,107 @@ type Failed<E> = WithKind<"Failed"> & WithErrors<E>;
1587
1611
  */
1588
1612
  type Validation<E, A> = Passed<A> | Failed<E>;
1589
1613
  declare namespace Validation {
1590
- /**
1591
- * Wraps a value in a passed Validation.
1592
- *
1593
- * @example
1594
- * ```ts
1595
- * Validation.passed(42); // Passed(42)
1596
- * ```
1597
- */
1598
- const passed: <E, A>(value: A) => Validation<E, A>;
1599
- /**
1600
- * Creates a failed Validation from a single error.
1601
- *
1602
- * @example
1603
- * ```ts
1604
- * Validation.failed("Invalid input");
1605
- * ```
1606
- */
1607
- const failed: <E>(error: E) => Failed<E>;
1608
- /**
1609
- * Creates a failed Validation from multiple errors.
1610
- *
1611
- * @example
1612
- * ```ts
1613
- * Validation.failedAll(["Invalid input"]);
1614
- * ```
1615
- */
1616
- const failedAll: <E>(errors: NonEmptyArr<E>) => Failed<E>;
1617
- /**
1618
- * Type guard that checks if a Validation is passed.
1619
- */
1620
- const isPassed: <E, A>(data: Validation<E, A>) => data is Passed<A>;
1621
- /**
1622
- * Type guard that checks if a Validation is failed.
1623
- */
1624
- const isFailed: <E, A>(data: Validation<E, A>) => data is Failed<E>;
1625
- /**
1626
- * Creates a Validation from a predicate applied to a value.
1627
- * Returns Passed if the predicate passes, Failed from `onFalse` otherwise.
1628
- *
1629
- * @example
1630
- * ```ts
1631
- * const validateName = Validation.fromPredicate(
1632
- * (s: string) => s.length > 0,
1633
- * () => "Name is required"
1634
- * );
1635
- *
1636
- * validateName("Alice"); // Passed("Alice")
1637
- * validateName(""); // Failed(["Name is required"])
1638
- * ```
1639
- */
1640
- const fromPredicate: <E, A>(pred: (a: A) => boolean, onFalse: (a: A) => E) => (a: A) => Validation<E, A>;
1641
- /**
1642
- * Creates a Validation from a nullable value.
1643
- * If the value is null or undefined, returns Failed with the error from onNull.
1644
- * Otherwise, returns Passed.
1645
- *
1646
- * @example
1647
- * ```ts
1648
- * pipe(null, Validation.fromNullable(() => "is null")); // Failed(["is null"])
1649
- * pipe(42, Validation.fromNullable(() => "is null")); // Passed(42)
1650
- * ```
1651
- */
1652
- const fromNullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => Validation<E, A>;
1653
- /**
1654
- * Creates a Validation from a Maybe.
1655
- * If the Maybe is None, returns Failed with the error from onNone.
1656
- * Otherwise, returns Passed.
1657
- *
1658
- * @example
1659
- * ```ts
1660
- * pipe(Maybe.none(), Validation.fromMaybe(() => "is none")); // Failed(["is none"])
1661
- * pipe(Maybe.some(42), Validation.fromMaybe(() => "is none")); // Passed(42)
1662
- * ```
1663
- */
1664
- const fromMaybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => Validation<E, A>;
1614
+ namespace make {
1615
+ /**
1616
+ * Wraps a value in a passed Validation.
1617
+ *
1618
+ * @example
1619
+ * ```ts
1620
+ * Validation.make.passed(42); // Passed(42)
1621
+ * ```
1622
+ */
1623
+ const passed: <E, A>(value: A) => Validation<E, A>;
1624
+ /**
1625
+ * Creates a failed Validation from a single error.
1626
+ *
1627
+ * @example
1628
+ * ```ts
1629
+ * Validation.make.failed("Invalid input");
1630
+ * ```
1631
+ */
1632
+ const failed: <E>(error: E) => Failed<E>;
1633
+ /**
1634
+ * Creates a failed Validation from multiple errors.
1635
+ *
1636
+ * @example
1637
+ * ```ts
1638
+ * Validation.make.failedAll(["Invalid input"]);
1639
+ * ```
1640
+ */
1641
+ const failedAll: <E>(errors: NonEmptyArr<E>) => Failed<E>;
1642
+ }
1643
+ namespace is {
1644
+ /**
1645
+ * Type guard that checks if a Validation is passed.
1646
+ */
1647
+ const passed: <E, A>(data: Validation<E, A>) => data is Passed<A>;
1648
+ /**
1649
+ * Type guard that checks if a Validation is failed.
1650
+ */
1651
+ const failed: <E, A>(data: Validation<E, A>) => data is Failed<E>;
1652
+ }
1653
+ namespace from {
1654
+ /**
1655
+ * Creates a Validation from a predicate applied to a value.
1656
+ * Returns Passed if the predicate passes, Failed from `onFalse` otherwise.
1657
+ *
1658
+ * @example
1659
+ * ```ts
1660
+ * const validateName = Validation.from.Predicate(
1661
+ * (s: string) => s.length > 0,
1662
+ * () => "Name is required"
1663
+ * );
1664
+ *
1665
+ * validateName("Alice"); // Passed("Alice")
1666
+ * validateName(""); // Failed(["Name is required"])
1667
+ * ```
1668
+ */
1669
+ const Predicate: <E, A>(pred: (a: A) => boolean, onFalse: (a: A) => E) => (a: A) => Validation<E, A>;
1670
+ /**
1671
+ * Creates a Validation from a nullable value.
1672
+ * If the value is null or undefined, returns Failed with the error from onNull.
1673
+ * Otherwise, returns Passed.
1674
+ *
1675
+ * @example
1676
+ * ```ts
1677
+ * pipe(null, Validation.from.nullable(() => "is null")); // Failed(["is null"])
1678
+ * pipe(42, Validation.from.nullable(() => "is null")); // Passed(42)
1679
+ * ```
1680
+ */
1681
+ const nullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => Validation<E, A>;
1682
+ /**
1683
+ * Creates a Validation from a Maybe.
1684
+ * If the Maybe is None, returns Failed with the error from onNone.
1685
+ * Otherwise, returns Passed.
1686
+ *
1687
+ * @example
1688
+ * ```ts
1689
+ * pipe(Maybe.make.none(), Validation.from.Maybe(() => "is none")); // Failed(["is none"])
1690
+ * pipe(Maybe.make.some(42), Validation.from.Maybe(() => "is none")); // Passed(42)
1691
+ * ```
1692
+ */
1693
+ const Maybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => Validation<E, A>;
1694
+ /**
1695
+ * Converts a `Result` to a `Validation`. `Ok` becomes `Passed`; `Err(e)` becomes `Failed([e])`.
1696
+ *
1697
+ * Useful when bridging from error-short-circuiting `Result` pipelines into
1698
+ * error-accumulating `Validation` pipelines.
1699
+ *
1700
+ * @example
1701
+ * ```ts
1702
+ * Validation.from.Result(Result.make.ok(42)); // Passed(42)
1703
+ * Validation.from.Result(Result.make.err("bad")); // Failed(["bad"])
1704
+ * ```
1705
+ */
1706
+ const Result: <E, A>(data: Result<E, A>) => Validation<E, A>;
1707
+ }
1665
1708
  /**
1666
1709
  * Transforms the success value inside a Validation.
1667
1710
  *
1668
1711
  * @example
1669
1712
  * ```ts
1670
- * pipe(Validation.passed(5), Validation.map(n => n * 2)); // Passed(10)
1671
- * pipe(Validation.failed("oops"), Validation.map(n => n * 2)); // Failed(["oops"])
1713
+ * pipe(Validation.make.passed(5), Validation.map(n => n * 2)); // Passed(10)
1714
+ * pipe(Validation.make.failed("oops"), Validation.map(n => n * 2)); // Failed(["oops"])
1672
1715
  * ```
1673
1716
  */
1674
1717
  const map: <A, B>(f: (a: A) => B) => <E>(data: Validation<E, A>) => Validation<E, B>;
@@ -1677,7 +1720,7 @@ declare namespace Validation {
1677
1720
  *
1678
1721
  * @example
1679
1722
  * ```ts
1680
- * pipe(Validation.failed("oops"), Validation.mapError(e => e.toUpperCase())); // Failed(["OOPS"])
1723
+ * pipe(Validation.make.failed("oops"), Validation.mapError(e => e.toUpperCase())); // Failed(["OOPS"])
1681
1724
  * ```
1682
1725
  */
1683
1726
  const mapError: <E, F, A>(f: (e: E) => F) => (data: Validation<E, A>) => Validation<F, A>;
@@ -1689,15 +1732,15 @@ declare namespace Validation {
1689
1732
  * ```ts
1690
1733
  * const add = (a: number) => (b: number) => a + b;
1691
1734
  * pipe(
1692
- * Validation.passed(add),
1693
- * Validation.ap(Validation.passed(5)),
1694
- * Validation.ap(Validation.passed(3))
1735
+ * Validation.make.passed(add),
1736
+ * Validation.ap(Validation.make.passed(5)),
1737
+ * Validation.ap(Validation.make.passed(3))
1695
1738
  * ); // Passed(8)
1696
1739
  *
1697
1740
  * pipe(
1698
- * Validation.passed(add),
1699
- * Validation.ap(Validation.failed<string, number>("bad a")),
1700
- * Validation.ap(Validation.failed<string, number>("bad b"))
1741
+ * Validation.make.passed(add),
1742
+ * Validation.ap(Validation.make.failed<string, number>("bad a")),
1743
+ * Validation.ap(Validation.make.failed<string, number>("bad b"))
1701
1744
  * ); // Failed(["bad a", "bad b"])
1702
1745
  * ```
1703
1746
  */
@@ -1708,7 +1751,7 @@ declare namespace Validation {
1708
1751
  * @example
1709
1752
  * ```ts
1710
1753
  * pipe(
1711
- * Validation.passed(42),
1754
+ * Validation.make.passed(42),
1712
1755
  * Validation.fold(
1713
1756
  * errors => `Errors: ${errors.join(", ")}`,
1714
1757
  * value => `Value: ${value}`
@@ -1741,9 +1784,9 @@ declare namespace Validation {
1741
1784
  *
1742
1785
  * @example
1743
1786
  * ```ts
1744
- * pipe(Validation.passed(5), Validation.getOrElse(() => 0)); // 5
1745
- * pipe(Validation.failed("oops"), Validation.getOrElse(() => 0)); // 0
1746
- * pipe(Validation.failed("oops"), Validation.getOrElse(() => null)); // null — typed as number | null
1787
+ * pipe(Validation.make.passed(5), Validation.getOrElse(() => 0)); // 5
1788
+ * pipe(Validation.make.failed("oops"), Validation.getOrElse(() => 0)); // 0
1789
+ * pipe(Validation.make.failed("oops"), Validation.getOrElse(() => null)); // null — typed as number | null
1747
1790
  * ```
1748
1791
  */
1749
1792
  const getOrElse: <E, A, B>(defaultValue: () => B) => (data: Validation<E, A>) => A | B;
@@ -1753,7 +1796,7 @@ declare namespace Validation {
1753
1796
  * @example
1754
1797
  * ```ts
1755
1798
  * pipe(
1756
- * Validation.passed(5),
1799
+ * Validation.make.passed(5),
1757
1800
  * Validation.tap(n => console.log("Value:", n)),
1758
1801
  * Validation.map(n => n * 2)
1759
1802
  * );
@@ -1767,7 +1810,7 @@ declare namespace Validation {
1767
1810
  * @example
1768
1811
  * ```ts
1769
1812
  * pipe(
1770
- * Validation.failed("Name required"),
1813
+ * Validation.make.failed("Name required"),
1771
1814
  * Validation.tapError(errors => console.error("validation failed:", errors)),
1772
1815
  * Validation.map(toUser)
1773
1816
  * );
@@ -1787,47 +1830,36 @@ declare namespace Validation {
1787
1830
  * @example
1788
1831
  * ```ts
1789
1832
  * pipe(
1790
- * Validation.failed("field-error"),
1791
- * Validation.recoverUnless(e => e === "fatal", () => Validation.passed(0))
1833
+ * Validation.make.failed("field-error"),
1834
+ * Validation.recoverUnless(e => e === "fatal", () => Validation.make.passed(0))
1792
1835
  * ); // Passed(0)
1793
1836
  * ```
1794
1837
  */
1795
1838
  const recoverUnless: <E, A, B>(isBlocked: (e: E) => boolean, fallback: () => Validation<E, B>) => (data: Validation<E, A>) => Validation<E, A | B>;
1796
- /**
1797
- * Converts a Validation to a Result.
1798
- * Passed becomes Ok, Failed becomes Err with the accumulated error list.
1799
- *
1800
- * @example
1801
- * ```ts
1802
- * Validation.toResult(Validation.passed(42)); // Ok(42)
1803
- * Validation.toResult(Validation.failed("oops")); // Err(["oops"])
1804
- * ```
1805
- */
1806
- const toResult: <E, A>(data: Validation<E, A>) => Result<NonEmptyArr<E>, A>;
1807
- /**
1808
- * Converts a Validation to a Maybe. `Passed` becomes `Some`; `Failed` becomes `None`
1809
- * (errors are discarded).
1810
- *
1811
- * @example
1812
- * ```ts
1813
- * Validation.toMaybe(Validation.passed(42)); // Some(42)
1814
- * Validation.toMaybe(Validation.failed("bad")); // None
1815
- * ```
1816
- */
1817
- const toMaybe: <E, A>(data: Validation<E, A>) => Maybe<A>;
1818
- /**
1819
- * Converts a `Result` to a `Validation`. `Ok` becomes `Passed`; `Err(e)` becomes `Failed([e])`.
1820
- *
1821
- * Useful when bridging from error-short-circuiting `Result` pipelines into
1822
- * error-accumulating `Validation` pipelines.
1823
- *
1824
- * @example
1825
- * ```ts
1826
- * Validation.fromResult(Result.ok(42)); // Passed(42)
1827
- * Validation.fromResult(Result.err("bad")); // Failed(["bad"])
1828
- * ```
1829
- */
1830
- const fromResult: <E, A>(data: Result<E, A>) => Validation<E, A>;
1839
+ namespace to {
1840
+ /**
1841
+ * Converts a Validation to a Result.
1842
+ * Passed becomes Ok, Failed becomes Err with the accumulated error list.
1843
+ *
1844
+ * @example
1845
+ * ```ts
1846
+ * Validation.to.Result(Validation.make.passed(42)); // Ok(42)
1847
+ * Validation.to.Result(Validation.make.failed("oops")); // Err(["oops"])
1848
+ * ```
1849
+ */
1850
+ const Result: <E, A>(data: Validation<E, A>) => Result<NonEmptyArr<E>, A>;
1851
+ /**
1852
+ * Converts a Validation to a Maybe. `Passed` becomes `Some`; `Failed` becomes `None`
1853
+ * (errors are discarded).
1854
+ *
1855
+ * @example
1856
+ * ```ts
1857
+ * Validation.to.Maybe(Validation.make.passed(42)); // Some(42)
1858
+ * Validation.to.Maybe(Validation.make.failed("bad")); // None
1859
+ * ```
1860
+ */
1861
+ const Maybe: <E, A>(data: Validation<E, A>) => Maybe<A>;
1862
+ }
1831
1863
  /**
1832
1864
  * Combines two independent Validation instances into a tuple.
1833
1865
  * If both are Passed, returns Passed with both values as a tuple.
@@ -1836,13 +1868,13 @@ declare namespace Validation {
1836
1868
  * @example
1837
1869
  * ```ts
1838
1870
  * Validation.product(
1839
- * Validation.passed("alice"),
1840
- * Validation.passed(30)
1871
+ * Validation.make.passed("alice"),
1872
+ * Validation.make.passed(30)
1841
1873
  * ); // Passed(["alice", 30])
1842
1874
  *
1843
1875
  * Validation.product(
1844
- * Validation.failed("Name required"),
1845
- * Validation.failed("Age must be >= 0")
1876
+ * Validation.make.failed("Name required"),
1877
+ * Validation.make.failed("Age must be >= 0")
1846
1878
  * ); // Failed(["Name required", "Age must be >= 0"])
1847
1879
  * ```
1848
1880
  */
@@ -1870,13 +1902,13 @@ declare namespace Validation {
1870
1902
  * @example
1871
1903
  * ```ts
1872
1904
  * Validation.struct({
1873
- * name: Validation.passed("Alice"),
1874
- * age: Validation.passed(30)
1905
+ * name: Validation.make.passed("Alice"),
1906
+ * age: Validation.make.passed(30)
1875
1907
  * }); // Passed({ name: "Alice", age: 30 })
1876
1908
  *
1877
1909
  * Validation.struct({
1878
- * name: Validation.failed("Name required"),
1879
- * age: Validation.failed("Age must be >= 0")
1910
+ * name: Validation.make.failed("Name required"),
1911
+ * age: Validation.make.failed("Age must be >= 0")
1880
1912
  * }); // Failed(["Name required", "Age must be >= 0"])
1881
1913
  * ```
1882
1914
  */