functype 0.49.0 → 0.51.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,10 +1,5 @@
1
- import { Brand } from "./branded/index.js";
2
- import { a as Serializable, c as Foldable, l as Type, n as Typeable, s as Pipe } from "./Typeable-lfO2nRVW.js";
3
- import { Try } from "./try/index.js";
4
- import { Set } from "./set/index.js";
5
- import { Option } from "./option/index.js";
6
- import { List } from "./list/index.js";
7
- import { Either } from "./either/index.js";
1
+ import { t as Brand } from "./Brand-BJIRbUKB.js";
2
+ import { c as Pipe, l as Foldable, o as Serializable, r as Typeable, t as Tuple, u as Type } from "./Tuple-DwyoW0ZP.js";
8
3
 
9
4
  //#region src/error/ParseError.d.ts
10
5
  declare const ParseError: (message?: string) => Error & {
@@ -141,6 +136,7 @@ interface LazyList<A extends Type> extends Foldable<A>, Pipe<LazyList<A>>, Seria
141
136
  get lastOption(): Option<A>;
142
137
  get tail(): LazyList<A>;
143
138
  get init(): LazyList<A>;
139
+ fold<B>(initial: B, fn: (acc: B, a: A) => B): B;
144
140
  toList(): List<A>;
145
141
  toArray(): A[];
146
142
  forEach(f: (a: A) => void): void;
@@ -282,6 +278,20 @@ interface ContainerOps<A extends Type> {
282
278
  * @typeParam Self - The collection type itself for proper return types
283
279
  */
284
280
  interface CollectionOps<A extends Type, Self> {
281
+ /**
282
+ * Left-associative fold over all elements using an initial value and combining function.
283
+ * Unlike foldLeft (which is curried), this provides a convenient uncurried signature.
284
+ *
285
+ * @example
286
+ * ```typescript
287
+ * List([1, 2, 3]).fold(0, (acc, x) => acc + x) // 6
288
+ * ```
289
+ *
290
+ * @param initial - The initial accumulator value
291
+ * @param fn - A function that combines the accumulator with each element
292
+ * @returns The final accumulated value
293
+ */
294
+ fold<B>(initial: B, fn: (acc: B, a: A) => B): B;
285
295
  /**
286
296
  * Drops the first n elements from the collection.
287
297
  */
@@ -416,6 +426,126 @@ interface Promisable<A extends Type> {
416
426
  toPromise(): Promise<A>;
417
427
  }
418
428
  //#endregion
429
+ //#region src/try/Try.d.ts
430
+ /**
431
+ * Possible types of Try instances
432
+ */
433
+ type TypeNames = "Success" | "Failure";
434
+ interface Try<T> extends FunctypeBase<T, TypeNames>, Extractable<T>, Pipe<T>, Promisable<T>, Doable<T>, Reshapeable<T> {
435
+ readonly _tag: TypeNames;
436
+ readonly error: Error | undefined;
437
+ isSuccess(): this is Try<T> & {
438
+ readonly _tag: "Success";
439
+ error: undefined;
440
+ };
441
+ isFailure(): this is Try<T> & {
442
+ readonly _tag: "Failure";
443
+ error: Error;
444
+ };
445
+ orElse: (defaultValue: T) => T;
446
+ orThrow: (error?: Error) => T;
447
+ or: (alternative: Try<T>) => Try<T>;
448
+ orNull: () => T | null;
449
+ orUndefined: () => T | undefined;
450
+ toOption: () => Option<T>;
451
+ toEither: <E extends Type>(leftValue: E) => Either<E, T>;
452
+ toList: () => List<T>;
453
+ toTry: () => Try<T>;
454
+ map: <U>(f: (value: T) => U) => Try<U>;
455
+ ap: <U>(ff: Try<(value: T) => U>) => Try<U>;
456
+ flatMap: <U>(f: (value: T) => Try<U>) => Try<U>;
457
+ flatMapAsync: <U>(f: (value: T) => Promise<Try<U>>) => Promise<Try<U>>;
458
+ /**
459
+ * Pattern matches over the Try, applying onFailure if Failure and onSuccess if Success
460
+ * @param onFailure - Function to apply if the Try is Failure
461
+ * @param onSuccess - Function to apply if the Try is Success
462
+ * @returns The result of applying the appropriate function
463
+ */
464
+ fold: <U extends Type>(onFailure: (error: Error) => U, onSuccess: (value: T) => U) => U;
465
+ toString: () => string;
466
+ /**
467
+ * Pattern matches over the Try, applying a handler function based on the variant
468
+ * @param patterns - Object with handler functions for Success and Failure variants
469
+ * @returns The result of applying the matching handler function
470
+ */
471
+ match<R>(patterns: {
472
+ Success: (value: T) => R;
473
+ Failure: (error: Error) => R;
474
+ }): R;
475
+ /**
476
+ * Recovers from a Failure by applying a function to the error, returning a new Try
477
+ * @param f - Function to apply to the error to produce a recovery value
478
+ * @returns Success with the recovery value if Failure, otherwise this
479
+ */
480
+ recover: (f: (error: Error) => T) => Try<T>;
481
+ /**
482
+ * Recovers from a Failure by applying a function that returns a new Try
483
+ * @param f - Function to apply to the error to produce a new Try
484
+ * @returns The result of f if Failure, otherwise this
485
+ */
486
+ recoverWith: (f: (error: Error) => Try<T>) => Try<T>;
487
+ toValue(): {
488
+ _tag: TypeNames;
489
+ value: T | Error;
490
+ };
491
+ }
492
+ declare const Try: (<T>(f: () => T) => Try<T>) & {
493
+ /**
494
+ * Creates a Success directly without needing a callback
495
+ * @param value - The success value
496
+ * @returns Try containing the value as Success
497
+ */
498
+ success: <T>(value: T) => Try<T>;
499
+ /**
500
+ * Creates a Failure directly without needing to throw
501
+ * @param error - The error (string or Error instance)
502
+ * @returns Try containing the error as Failure
503
+ */
504
+ failure: <T>(error: Error | string) => Try<T>;
505
+ /**
506
+ * Creates a Try from a Promise, resolving to Success or Failure
507
+ * @param promise - The promise to convert
508
+ * @returns Promise resolving to a Try
509
+ */
510
+ fromPromise: <T>(promise: Promise<T>) => Promise<Try<T>>;
511
+ /**
512
+ * Type guard to check if a Try is Success
513
+ * @param tryValue - The Try to check
514
+ * @returns True if Try is Success
515
+ */
516
+ isSuccess: <T>(tryValue: Try<T>) => tryValue is Try<T> & {
517
+ readonly _tag: "Success";
518
+ error: undefined;
519
+ };
520
+ /**
521
+ * Type guard to check if a Try is Failure
522
+ * @param tryValue - The Try to check
523
+ * @returns True if Try is Failure
524
+ */
525
+ isFailure: <T>(tryValue: Try<T>) => tryValue is Try<T> & {
526
+ readonly _tag: "Failure";
527
+ error: Error;
528
+ };
529
+ /**
530
+ * Creates a Try from JSON string
531
+ * @param json - The JSON string
532
+ * @returns Try instance
533
+ */
534
+ fromJSON: <T>(json: string) => Try<T>;
535
+ /**
536
+ * Creates a Try from YAML string
537
+ * @param yaml - The YAML string
538
+ * @returns Try instance
539
+ */
540
+ fromYAML: <T>(yaml: string) => Try<T>;
541
+ /**
542
+ * Creates a Try from binary string
543
+ * @param binary - The binary string
544
+ * @returns Try instance
545
+ */
546
+ fromBinary: <T>(binary: string) => Try<T>;
547
+ };
548
+ //#endregion
419
549
  //#region src/reshapeable/Reshapeable.d.ts
420
550
  /**
421
551
  * Interface for types that can be reshaped (converted) between different monadic containers.
@@ -1675,45 +1805,54 @@ declare const Validation: (<T extends Type>(rule: ValidationRule) => Validator<T
1675
1805
  //#endregion
1676
1806
  //#region src/foldable/index.d.ts
1677
1807
  /**
1678
- * Utility functions for working with Foldable data structures
1808
+ * Structural type for sum types that support pattern-match fold (Option, Either, Try, etc.).
1809
+ * Uses duck typing so any type with the right fold signature works, without requiring a shared interface.
1810
+ */
1811
+ type PatternFoldable<A> = {
1812
+ fold<B>(onEmpty: () => B, onValue: (value: A) => B): B;
1813
+ };
1814
+ /**
1815
+ * Utility functions for working with sum-type Foldable data structures.
1816
+ * These utilities use pattern-match fold semantics and are designed for
1817
+ * sum types (Option, Either, Try) — not collections.
1679
1818
  */
1680
1819
  declare const FoldableUtils: {
1681
1820
  /**
1682
- * Converts a Foldable to an Option
1821
+ * Converts a sum type to an Option
1683
1822
  *
1684
- * @param foldable - The foldable structure to convert
1823
+ * @param foldable - The sum type to convert
1685
1824
  * @returns An Option containing the value, or None if empty
1686
1825
  */
1687
- toOption: <A extends Type>(foldable: Foldable<A>) => Option<A>;
1826
+ toOption: <A extends Type>(foldable: PatternFoldable<A>) => Option<A>;
1688
1827
  /**
1689
- * Converts a Foldable to a List
1828
+ * Converts a sum type to a List
1690
1829
  *
1691
- * @param foldable - The foldable structure to convert
1830
+ * @param foldable - The sum type to convert
1692
1831
  * @returns A List containing the value(s), or empty List if empty
1693
1832
  */
1694
- toList: <A extends Type>(foldable: Foldable<A>) => List<A>;
1833
+ toList: <A extends Type>(foldable: PatternFoldable<A>) => List<A>;
1695
1834
  /**
1696
- * Converts a Foldable to an Either
1835
+ * Converts a sum type to an Either
1697
1836
  *
1698
- * @param foldable - The foldable structure to convert
1837
+ * @param foldable - The sum type to convert
1699
1838
  * @param left - The value to use for Left if empty
1700
1839
  * @returns Either.Right with the value if non-empty, or Either.Left with left if empty
1701
1840
  */
1702
- toEither: <A extends Type, E>(foldable: Foldable<A>, left: E) => Either<E, A>;
1841
+ toEither: <A extends Type, E>(foldable: PatternFoldable<A>, left: E) => Either<E, A>;
1703
1842
  /**
1704
- * Checks if the Foldable is empty
1843
+ * Checks if the sum type is empty
1705
1844
  *
1706
- * @param foldable - The foldable structure to check
1845
+ * @param foldable - The sum type to check
1707
1846
  * @returns true if empty, false otherwise
1708
1847
  */
1709
- isEmpty: <A extends Type>(foldable: Foldable<A>) => boolean;
1848
+ isEmpty: <A extends Type>(foldable: PatternFoldable<A>) => boolean;
1710
1849
  /**
1711
- * Calculates the size of the Foldable
1850
+ * Calculates the size of the sum type (0 or 1)
1712
1851
  *
1713
- * @param foldable - The foldable structure to measure
1714
- * @returns The size (number of elements)
1852
+ * @param foldable - The sum type to measure
1853
+ * @returns The size (0 if empty, 1 if non-empty)
1715
1854
  */
1716
- size: <A extends Type>(foldable: Foldable<A>) => number;
1855
+ size: <A extends Type>(foldable: PatternFoldable<A>) => number;
1717
1856
  };
1718
1857
  //#endregion
1719
1858
  //#region src/hkt/index.d.ts
@@ -3435,6 +3574,73 @@ interface Traversable<A extends Type> extends AsyncMonad<A> {
3435
3574
  reduceRight(f: (b: A, a: A) => A): A;
3436
3575
  }
3437
3576
  //#endregion
3577
+ //#region src/map/Map.d.ts
3578
+ /**
3579
+ * A traversable interface for map that excludes map and flatMap operations
3580
+ */
3581
+ type SafeTraversable<K, V> = Omit<Traversable<Tuple<[K, V]>>, "map" | "flatMap" | "flatMapAsync" | "ap">;
3582
+ interface Map$1<K, V> extends SafeTraversable<K, V>, Collection<Tuple<[K, V]>>, Typeable<"Map">, Serializable<[K, V][]>, Pipe<[K, V][]>, Foldable<Tuple<[K, V]>>, Iterable<[K, V]> {
3583
+ readonly [Symbol.toStringTag]: string;
3584
+ readonly _tag: "Map";
3585
+ add(item: Tuple<[K, V]>): Map$1<K, V>;
3586
+ remove(value: K): Map$1<K, V>;
3587
+ map<U>(f: (value: V) => U): Map$1<K, U>;
3588
+ ap<U>(ff: Map$1<K, (value: V) => U>): Map$1<K, U>;
3589
+ flatMap<K2, V2>(f: (entry: Tuple<[K, V]>) => Iterable<[K2, V2]>): Map$1<K2, V2>;
3590
+ flatMapAsync<U>(f: (value: V) => PromiseLike<Map$1<K, U>>): PromiseLike<Map$1<K, U>>;
3591
+ get(key: K): Option<V>;
3592
+ getOrElse(key: K, defaultValue: V): V;
3593
+ orElse(key: K, alternative: Option<V>): Option<V>;
3594
+ fold<B>(initial: B, fn: (acc: B, a: Tuple<[K, V]>) => B): B;
3595
+ foldLeft<B>(z: B): (op: (b: B, a: Tuple<[K, V]>) => B) => B;
3596
+ foldRight<B>(z: B): (op: (a: Tuple<[K, V]>, b: B) => B) => B;
3597
+ /**
3598
+ * Pattern matches over the Map, applying a handler function based on whether it's empty
3599
+ * @param patterns - Object with handler functions for Empty and NonEmpty variants
3600
+ * @returns The result of applying the matching handler function
3601
+ */
3602
+ match<R>(patterns: {
3603
+ Empty: () => R;
3604
+ NonEmpty: (entries: Array<Tuple<[K, V]>>) => R;
3605
+ }): R;
3606
+ toValue(): {
3607
+ _tag: "Map";
3608
+ value: [K, V][];
3609
+ };
3610
+ }
3611
+ declare const Map$1: (<K, V>(entries?: readonly (readonly [K, V])[] | IterableIterator<[K, V]> | null) => Map$1<K, V>) & {
3612
+ /**
3613
+ * Creates an empty Map
3614
+ * Returns a singleton instance for efficiency
3615
+ * @returns An empty Map instance
3616
+ */
3617
+ empty: <K, V>() => Map$1<K, V>;
3618
+ /**
3619
+ * Creates a Map from variadic key-value pair arguments
3620
+ * @param entries - Key-value pairs to create map from
3621
+ * @returns A Map containing the entries
3622
+ */
3623
+ of: <K, V>(...entries: [K, V][]) => Map$1<K, V>;
3624
+ /**
3625
+ * Creates a Map from JSON string
3626
+ * @param json - The JSON string
3627
+ * @returns Map instance
3628
+ */
3629
+ fromJSON: <K, V>(json: string) => Map$1<K, V>;
3630
+ /**
3631
+ * Creates a Map from YAML string
3632
+ * @param yaml - The YAML string
3633
+ * @returns Map instance
3634
+ */
3635
+ fromYAML: <K, V>(yaml: string) => Map$1<K, V>;
3636
+ /**
3637
+ * Creates a Map from binary string
3638
+ * @param binary - The binary string
3639
+ * @returns Map instance
3640
+ */
3641
+ fromBinary: <K, V>(binary: string) => Map$1<K, V>;
3642
+ };
3643
+ //#endregion
3438
3644
  //#region src/map/shim.d.ts
3439
3645
  /**
3440
3646
  * Type alias for the native JavaScript Map
@@ -3615,6 +3821,55 @@ declare const createSerializationCompanion: <T>(reconstructor: (parsed: {
3615
3821
  fromBinary: (binary: string) => T;
3616
3822
  };
3617
3823
  //#endregion
3824
+ //#region src/set/Set.d.ts
3825
+ interface Set<A> extends FunctypeCollection<A, "Set">, Collection<A> {
3826
+ add: (value: A) => Set<A>;
3827
+ remove: (value: A) => Set<A>;
3828
+ contains: (value: A) => boolean;
3829
+ has: (value: A) => boolean;
3830
+ map: <B>(f: (a: A) => B) => Set<B>;
3831
+ flatMap: <B>(f: (a: A) => Iterable<B>) => Set<B>;
3832
+ filter: (p: (a: A) => boolean) => Set<A>;
3833
+ filterNot: (p: (a: A) => boolean) => Set<A>;
3834
+ fold: <B>(initial: B, fn: (acc: B, a: A) => B) => B;
3835
+ toList: () => List<A>;
3836
+ toSet: () => Set<A>;
3837
+ toArray: <B = A>() => B[];
3838
+ toString: () => string;
3839
+ }
3840
+ declare const Set: (<A>(iterable?: Iterable<A>) => Set<A>) & {
3841
+ /**
3842
+ * Creates an empty Set
3843
+ * Returns a singleton instance for efficiency
3844
+ * @returns An empty Set instance
3845
+ */
3846
+ empty: <A extends Type>() => Set<A>;
3847
+ /**
3848
+ * Creates a Set from variadic arguments
3849
+ * @param values - Values to create set from
3850
+ * @returns A Set containing the unique values
3851
+ */
3852
+ of: <A extends Type>(...values: A[]) => Set<A>;
3853
+ /**
3854
+ * Creates a Set from JSON string
3855
+ * @param json - The JSON string
3856
+ * @returns Set instance
3857
+ */
3858
+ fromJSON: <A>(json: string) => Set<A>;
3859
+ /**
3860
+ * Creates a Set from YAML string
3861
+ * @param yaml - The YAML string
3862
+ * @returns Set instance
3863
+ */
3864
+ fromYAML: <A>(yaml: string) => Set<A>;
3865
+ /**
3866
+ * Creates a Set from binary string
3867
+ * @param binary - The binary string
3868
+ * @returns Set instance
3869
+ */
3870
+ fromBinary: <A>(binary: string) => Set<A>;
3871
+ };
3872
+ //#endregion
3618
3873
  //#region src/valuable/Valuable.d.ts
3619
3874
  /**
3620
3875
  * Parameters for creating a Valuable instance
@@ -3706,6 +3961,10 @@ type Stack<A extends Type> = {
3706
3961
  * @returns A string representation
3707
3962
  */
3708
3963
  toString(): string;
3964
+ /**
3965
+ * Left-associative fold over all elements using an initial value and combining function.
3966
+ */
3967
+ fold<B>(initial: B, fn: (acc: B, a: A) => B): B;
3709
3968
  /**
3710
3969
  * Pattern matches over the Stack, applying a handler function based on whether it's empty
3711
3970
  * @param patterns - Object with handler functions for Empty and NonEmpty variants
@@ -3748,6 +4007,323 @@ declare const Stack: (<A extends Type>(values?: A[]) => Stack<A>) & {
3748
4007
  fromBinary: <A>(binary: string) => Stack<A>;
3749
4008
  };
3750
4009
  //#endregion
4010
+ //#region src/option/Option.d.ts
4011
+ /**
4012
+ * Option type module
4013
+ * @module Option
4014
+ * @category Core
4015
+ */
4016
+ /**
4017
+ * The Option type represents a value that may or may not exist.
4018
+ * It's used to handle potentially null or undefined values in a type-safe way.
4019
+ * @typeParam T - The type of the value contained in the Option
4020
+ */
4021
+ interface Option<T extends Type> extends Functype<T, "Some" | "None">, Promisable<T>, Doable<T>, Reshapeable<T> {
4022
+ /** The contained value (undefined for None) */
4023
+ readonly value: T | undefined;
4024
+ /** Whether this Option contains no value */
4025
+ isEmpty: boolean;
4026
+ /**
4027
+ * Returns true if this Option is a Some (contains a value)
4028
+ * @returns true if this Option contains a value, false otherwise
4029
+ */
4030
+ isSome(): this is Option<T> & {
4031
+ value: T;
4032
+ isEmpty: false;
4033
+ };
4034
+ /**
4035
+ * Returns true if this Option is a None (contains no value)
4036
+ * @returns true if this Option is empty, false otherwise
4037
+ */
4038
+ isNone(): this is Option<T> & {
4039
+ value: undefined;
4040
+ isEmpty: true;
4041
+ };
4042
+ /**
4043
+ * Returns the contained value or a default value if None
4044
+ * @param defaultValue - The value to return if this Option is None
4045
+ * @returns The contained value or defaultValue
4046
+ */
4047
+ orElse(defaultValue: T): T;
4048
+ /**
4049
+ * Returns the contained value or throws an error if None
4050
+ * @param error - Optional custom error to throw. If not provided, throws a default error
4051
+ * @returns The contained value
4052
+ * @throws The specified error or a default error if the Option is None
4053
+ */
4054
+ orThrow(error?: Error): T;
4055
+ /**
4056
+ * Returns this Option if it contains a value, otherwise returns the alternative container
4057
+ * @param alternative - The alternative Option to return if this is None
4058
+ * @returns This Option or the alternative
4059
+ */
4060
+ or(alternative: Option<T>): Option<T>;
4061
+ /**
4062
+ * Returns the contained value or null if None
4063
+ * @returns The contained value or null
4064
+ */
4065
+ orNull(): T | null;
4066
+ /**
4067
+ * Returns the contained value or undefined if None
4068
+ * @returns The contained value or undefined
4069
+ */
4070
+ orUndefined(): T | undefined;
4071
+ /**
4072
+ * Maps the value inside the Option using the provided function
4073
+ * @param f - The mapping function
4074
+ * @returns A new Option containing the mapped value, or None if this Option is None
4075
+ */
4076
+ map<U extends Type>(f: (value: T) => U): Option<U>;
4077
+ /**
4078
+ * Applies a wrapped function to a wrapped value (Applicative pattern)
4079
+ * @param ff - An Option containing a function from T to U
4080
+ * @returns A new Option containing the result of applying the function
4081
+ */
4082
+ ap<U extends Type>(ff: Option<(value: T) => U>): Option<U>;
4083
+ /**
4084
+ * Returns this Option if it contains a value that satisfies the predicate, otherwise returns None
4085
+ * @param predicate - The predicate function to test the value
4086
+ * @returns This Option or None
4087
+ */
4088
+ filter(predicate: (value: T) => boolean): Option<T>;
4089
+ /**
4090
+ * Maps the value using a function that returns an Option
4091
+ * @param f - The mapping function returning an Option
4092
+ * @returns The result of applying f to the contained value, or None if this Option is None
4093
+ */
4094
+ flatMap<U extends Type>(f: (value: T) => Option<U>): Option<U>;
4095
+ /**
4096
+ * Maps the value using an async function that returns an Option
4097
+ * @param f - The async mapping function returning an Option
4098
+ * @returns Promise of the result of applying f to the contained value, or None if this Option is None
4099
+ */
4100
+ flatMapAsync<U extends Type>(f: (value: T) => Promise<Option<U>>): Promise<Option<U>>;
4101
+ /**
4102
+ * Applies a binary operator to a start value and the contained value
4103
+ * @param f - The binary operator
4104
+ * @returns The result of the reduction
4105
+ */
4106
+ reduce<U>(f: (acc: U, value: T) => U): U;
4107
+ /**
4108
+ * Applies a binary operator to the contained value and a start value
4109
+ * @param f - The binary operator
4110
+ * @returns The result of the reduction
4111
+ */
4112
+ reduceRight<U>(f: (acc: U, value: T) => U): U;
4113
+ /**
4114
+ * Pattern matches over the Option, applying onNone if None and onSome if Some
4115
+ * @param onNone - Function to apply if the Option is None
4116
+ * @param onSome - Function to apply if the Option has a value
4117
+ * @returns The result of applying the appropriate function
4118
+ */
4119
+ fold<U>(onNone: () => U, onSome: (value: T) => U): U;
4120
+ /**
4121
+ * Left-associative fold using the provided zero value and operation
4122
+ * @param z - Zero/identity value
4123
+ * @returns A function that takes an operation to apply
4124
+ */
4125
+ foldLeft<B>(z: B): (op: (b: B, a: T) => B) => B;
4126
+ /**
4127
+ * Right-associative fold using the provided zero value and operation
4128
+ * @param z - Zero/identity value
4129
+ * @returns A function that takes an operation to apply
4130
+ */
4131
+ foldRight<B>(z: B): (op: (a: T, b: B) => B) => B;
4132
+ /**
4133
+ * Converts this Option to a List
4134
+ * @returns A List containing the value if Some, or empty List if None
4135
+ */
4136
+ toList(): List<T>;
4137
+ /**
4138
+ * Checks if this Option contains the specified value
4139
+ * @param value - The value to check for
4140
+ * @returns true if this Option contains the value, false otherwise
4141
+ */
4142
+ contains(value: T): boolean;
4143
+ /** The number of elements in this Option (0 or 1) */
4144
+ size: number;
4145
+ /**
4146
+ * Converts this Option to an Either
4147
+ * @param left - The value to use for Left if this Option is None
4148
+ * @returns Either.Right with the contained value if Some, or Either.Left with left if None
4149
+ */
4150
+ toEither<E>(left: E): Either<E, T>;
4151
+ /**
4152
+ * Returns a string representation of this Option
4153
+ * @returns A string representation
4154
+ */
4155
+ toString(): string;
4156
+ /**
4157
+ * Returns a simple object representation of this Option
4158
+ * @returns An object with _tag and value properties
4159
+ */
4160
+ toValue(): {
4161
+ _tag: "Some" | "None";
4162
+ value: T;
4163
+ };
4164
+ /**
4165
+ * Pattern matches over the Option, applying a handler function based on the variant
4166
+ * @param patterns - Object with handler functions for Some and None variants
4167
+ * @returns The result of applying the matching handler function
4168
+ */
4169
+ match<R>(patterns: {
4170
+ Some: (value: T) => R;
4171
+ None: () => R;
4172
+ }): R;
4173
+ }
4174
+ /**
4175
+ * Creates a Some variant of Option containing a value.
4176
+ * @param value - The value to wrap in Some
4177
+ * @returns A new Some instance containing the value
4178
+ * @typeParam T - The type of the value
4179
+ */
4180
+ declare const Some: <T extends Type>(value: T) => Option<T>;
4181
+ /**
4182
+ * Creates a None variant of Option representing absence of a value.
4183
+ * @returns A new None instance
4184
+ * @typeParam T - The type that would be contained if this was a Some
4185
+ */
4186
+ declare const None: <T extends Type>() => Option<T>;
4187
+ /**
4188
+ * Safely wraps a value that might be null or undefined in an Option.
4189
+ * Creates Some if the value is defined, None otherwise.
4190
+ * @param value - The value to wrap (might be null/undefined)
4191
+ * @returns Some(value) if value is defined, None otherwise
4192
+ * @typeParam T - The type of the value
4193
+ */
4194
+ declare const OptionConstructor: <T extends Type>(value: T | null | undefined) => Option<T>;
4195
+ declare const Option: (<T extends Type>(value: T | null | undefined) => Option<T>) & {
4196
+ /**
4197
+ * Creates an Option from any value. Alias for Option function.
4198
+ * @param value - The value to wrap
4199
+ * @returns Some(value) if value is defined, None otherwise
4200
+ * @typeParam T - The type of the value
4201
+ */
4202
+ from: <T>(value: T) => Option<T>;
4203
+ /**
4204
+ * Returns a None instance. Alias for None function.
4205
+ * @returns A None instance
4206
+ * @typeParam T - The type that would be contained if this was a Some
4207
+ */
4208
+ none: <T>() => Option<T>;
4209
+ /**
4210
+ * Type guard to check if an Option is Some
4211
+ * @param option - The Option to check
4212
+ * @returns True if Option is Some
4213
+ */
4214
+ isSome: <T>(option: Option<T>) => option is Option<T> & {
4215
+ value: T;
4216
+ isEmpty: false;
4217
+ };
4218
+ /**
4219
+ * Type guard to check if an Option is None
4220
+ * @param option - The Option to check
4221
+ * @returns True if Option is None
4222
+ */
4223
+ isNone: <T>(option: Option<T>) => option is Option<T> & {
4224
+ value: undefined;
4225
+ isEmpty: true;
4226
+ };
4227
+ /**
4228
+ * Creates an Option from JSON string
4229
+ * @param json - The JSON string
4230
+ * @returns Option instance
4231
+ */
4232
+ fromJSON: <T>(json: string) => Option<T>;
4233
+ /**
4234
+ * Creates an Option from YAML string
4235
+ * @param yaml - The YAML string
4236
+ * @returns Option instance
4237
+ */
4238
+ fromYAML: <T>(yaml: string) => Option<T>;
4239
+ /**
4240
+ * Creates an Option from binary string
4241
+ * @param binary - The binary string
4242
+ * @returns Option instance
4243
+ */
4244
+ fromBinary: <T>(binary: string) => Option<T>;
4245
+ };
4246
+ //#endregion
4247
+ //#region src/list/List.d.ts
4248
+ interface List<A> extends FunctypeCollection<A, "List">, Doable<A>, Reshapeable<A> {
4249
+ readonly length: number;
4250
+ readonly [Symbol.iterator]: () => Iterator<A>;
4251
+ map: <B>(f: (a: A) => B) => List<B>;
4252
+ ap: <B>(ff: List<(value: A) => B>) => List<B>;
4253
+ flatMap: <B>(f: (a: A) => Iterable<B>) => List<B>;
4254
+ flatMapAsync: <B>(f: (a: A) => PromiseLike<Iterable<B>>) => PromiseLike<List<B>>;
4255
+ filter<S extends A>(predicate: (a: A) => a is S): List<S>;
4256
+ filter(predicate: (a: A) => unknown): List<A>;
4257
+ filterNot: (p: (a: A) => boolean) => List<A>;
4258
+ /** @internal */
4259
+ filterType: <T extends Typeable<string, unknown>>(tag: string) => List<T & A>;
4260
+ remove: (value: A) => List<A>;
4261
+ removeAt: (index: number) => List<A>;
4262
+ add: (item: A) => List<A>;
4263
+ get: (index: number) => Option<A>;
4264
+ concat: (other: List<A>) => List<A>;
4265
+ take: (n: number) => List<A>;
4266
+ takeWhile: (p: (a: A) => boolean) => List<A>;
4267
+ takeRight: (n: number) => List<A>;
4268
+ get last(): A | undefined;
4269
+ get lastOption(): Option<A>;
4270
+ get tail(): List<A>;
4271
+ get init(): List<A>;
4272
+ reverse: () => List<A>;
4273
+ indexOf: (value: A) => number;
4274
+ prepend: (item: A) => List<A>;
4275
+ distinct: () => List<A>;
4276
+ sorted: (compareFn?: (a: A, b: A) => number) => List<A>;
4277
+ sortBy: <B>(f: (a: A) => B, compareFn?: (a: B, b: B) => number) => List<A>;
4278
+ zip: <B>(other: List<B>) => List<[A, B]>;
4279
+ zipWithIndex: () => List<[A, number]>;
4280
+ groupBy: <K>(f: (a: A) => K) => globalThis.Map<K, List<A>>;
4281
+ partition: (p: (a: A) => boolean) => [List<A>, List<A>];
4282
+ span: (p: (a: A) => boolean) => [List<A>, List<A>];
4283
+ slice: (start: number, end: number) => List<A>;
4284
+ /**
4285
+ * Pattern matches over the List, applying a handler function based on whether it's empty
4286
+ * @param patterns - Object with handler functions for Empty and NonEmpty variants
4287
+ * @returns The result of applying the matching handler function
4288
+ */
4289
+ match<R>(patterns: {
4290
+ Empty: () => R;
4291
+ NonEmpty: (values: A[]) => R;
4292
+ }): R;
4293
+ }
4294
+ declare const List: (<A>(values?: Iterable<A>) => List<A>) & {
4295
+ /**
4296
+ * Creates an empty List
4297
+ * Returns a singleton instance for efficiency
4298
+ * @returns An empty List instance
4299
+ */
4300
+ empty: <A extends Type>() => List<A>;
4301
+ /**
4302
+ * Creates a List from variadic arguments
4303
+ * @param values - Values to create list from
4304
+ * @returns A List containing the values
4305
+ */
4306
+ of: <A extends Type>(...values: A[]) => List<A>;
4307
+ /**
4308
+ * Creates a List from JSON string
4309
+ * @param json - The JSON string
4310
+ * @returns List instance
4311
+ */
4312
+ fromJSON: <A>(json: string) => List<A>;
4313
+ /**
4314
+ * Creates a List from YAML string
4315
+ * @param yaml - The YAML string
4316
+ * @returns List instance
4317
+ */
4318
+ fromYAML: <A>(yaml: string) => List<A>;
4319
+ /**
4320
+ * Creates a List from binary string
4321
+ * @param binary - The binary string
4322
+ * @returns List instance
4323
+ */
4324
+ fromBinary: <A>(binary: string) => List<A>;
4325
+ };
4326
+ //#endregion
3751
4327
  //#region src/collections/index.d.ts
3752
4328
  /**
3753
4329
  * Represents a collection with conversion capabilities
@@ -3810,4 +4386,363 @@ interface FunctypeCollection<A, Tag extends string = string> extends Omit<Functy
3810
4386
  flatMapAsync<B extends Type>(f: (value: A) => PromiseLike<Iterable<B>>): PromiseLike<FunctypeCollection<B, Tag>>;
3811
4387
  }
3812
4388
  //#endregion
3813
- export { Validation as $, UrlString as $t, UIO as A, isTaggedThrowable as At, Tag as B, isCompanion as Bt, TestClockTag as C, TaskFailure as Ct, RIO as D, TaskResult as Dt, InterruptedError as E, TaskParams as Et, Exit as F, Match as Ft, Kind as G, ISO8601Date as Gt, Identity as H, BoundedNumber as Ht, ExitTag as I, UntypedMatch as It, TryKind as J, NonNegativeNumber as Jt, ListKind as K, IntegerNumber as Kt, Context as L, Cond as Lt, LayerError as M, Throwable as Mt, LayerInput as N, ThrowableType as Nt, Task as O, TaskSuccess as Ot, LayerOutput as P, Base as Pt, FormValidation as Q, UUID as Qt, ContextServices as R, CompanionMethods as Rt, TestClock as S, Task$1 as St, IO as T, TaskOutcome as Tt, EitherKind as U, BoundedString as Ut, TagService as V, Companion as Vt, HKT as W, EmailAddress as Wt, FoldableUtils as X, PositiveInteger as Xt, UniversalContainer as Y, PatternString as Yt, FieldValidation as Z, PositiveNumber as Zt, MatchableUtils as _, CancellationTokenSource as _t, Stack as a, AsyncMonad as an, TypedError as at, Traversable as b, Sync as bt, SerializationResult as c, CollectionOps as cn, ErrorFormatterOptions as ct, createSerializer as d, Extractable as dn, createErrorSerializer as dt, ValidatedBrand as en, ValidationRule as et, fromBinary as f, isExtractable as fn, formatError as ft, Matchable as g, CancellationToken as gt, Ref as h, ParseError as hn, Async as ht, Collection as i, Applicative as in, ErrorStatus as it, Layer as j, NAME as jt, TimeoutError as k, createCancellationTokenSource as kt, createCustomSerializer as l, ContainerOps as ln, ErrorWithTaskInfo as lt, fromYAML as m, Doable as mn, safeStringify as mt, FunctypeBase as n, Reshapeable as nn, ErrorCode as nt, Valuable as o, Functor as on, TypedErrorContext as ot, fromJSON as p, DoResult as pn, formatStackTrace as pt, OptionKind as q, NonEmptyString as qt, FunctypeCollection as r, Promisable as rn, ErrorMessage as rt, ValuableParams as s, Monad as sn, ErrorChainElement as st, Functype as t, ValidatedBrandCompanion as tn, Validator as tt, createSerializationCompanion as u, LazyList as un, TaskErrorInfo as ut, ESMap as v, Err as vt, TestContext as w, TaskMetadata as wt, Lazy as x, TaggedThrowable as xt, ESMapType as y, Ok as yt, HasService as z, InstanceType as zt };
4389
+ //#region src/either/Either.d.ts
4390
+ /**
4391
+ * Either type module
4392
+ * @module Either
4393
+ * @category Core
4394
+ */
4395
+ interface Either<L extends Type, R extends Type> extends FunctypeBase<R, "Left" | "Right">, Promisable<R>, Doable<R>, Reshapeable<R>, Extractable<R> {
4396
+ readonly _tag: "Left" | "Right";
4397
+ value: L | R;
4398
+ isLeft(): this is Either<L, R> & {
4399
+ readonly _tag: "Left";
4400
+ value: L;
4401
+ };
4402
+ isRight(): this is Either<L, R> & {
4403
+ readonly _tag: "Right";
4404
+ value: R;
4405
+ };
4406
+ orElse: (defaultValue: R) => R;
4407
+ orThrow: (error?: Error) => R;
4408
+ or(alternative: Either<L, R>): Either<L, R>;
4409
+ orNull: () => R | null;
4410
+ orUndefined: () => R | undefined;
4411
+ readonly map: <U extends Type>(f: (value: R) => U) => Either<L, U>;
4412
+ ap: <U extends Type>(ff: Either<L, (value: R) => U>) => Either<L, U>;
4413
+ merge: <L1 extends Type, R1 extends Type>(other: Either<L1, R1>) => Either<L | L1, [R, R1]>;
4414
+ mapAsync: <U extends Type>(f: (value: R) => Promise<U>) => Promise<Either<L, U>>;
4415
+ flatMap: <U extends Type>(f: (value: R) => Either<L, U>) => Either<L, U>;
4416
+ flatMapAsync: <U extends Type>(f: (value: R) => Promise<Either<L, U>>) => Promise<Either<L, U>>;
4417
+ toOption: () => Option<R>;
4418
+ toList: () => List<R>;
4419
+ toString: () => string;
4420
+ [Symbol.iterator]: () => Iterator<R>;
4421
+ yield: () => Generator<R, void, unknown>;
4422
+ traverse: <U extends Type>(f: (value: R) => Either<L, U>) => Either<L, U[]>;
4423
+ lazyMap: <U extends Type>(f: (value: R) => U) => Generator<Either<L, U>, void, unknown>;
4424
+ tap: (f: (value: R) => void) => Either<L, R>;
4425
+ tapLeft: (f: (value: L) => void) => Either<L, R>;
4426
+ mapLeft: <L2 extends Type>(f: (value: L) => L2) => Either<L2, R>;
4427
+ bimap: <L2 extends Type, R2 extends Type>(fl: (value: L) => L2, fr: (value: R) => R2) => Either<L2, R2>;
4428
+ fold: <T extends Type>(onLeft: (value: L) => T, onRight: (value: R) => T) => T;
4429
+ swap: () => Either<R, L>;
4430
+ /**
4431
+ * Pipes the value through the provided function based on whether this is a Left or Right
4432
+ * @param onLeft - The function to apply if this is a Left
4433
+ * @param onRight - The function to apply if this is a Right
4434
+ * @returns The result of applying the appropriate function
4435
+ */
4436
+ pipeEither<U extends Type>(onLeft: (value: L) => U, onRight: (value: R) => U): U;
4437
+ /**
4438
+ * Pipes the Either value through the provided function
4439
+ * @param f - The function to apply to the value (Left or Right)
4440
+ * @returns The result of applying the function to the value
4441
+ */
4442
+ pipe<U extends Type>(f: (value: L | R) => U): U;
4443
+ /**
4444
+ * Pattern matches over the Either, applying a handler function based on the variant
4445
+ * @param patterns - Object with handler functions for Left and Right variants
4446
+ * @returns The result of applying the matching handler function
4447
+ */
4448
+ match<T>(patterns: {
4449
+ Left: (value: L) => T;
4450
+ Right: (value: R) => T;
4451
+ }): T;
4452
+ /**
4453
+ * Returns the value and tag for inspection
4454
+ */
4455
+ toValue(): {
4456
+ _tag: "Left" | "Right";
4457
+ value: L | R;
4458
+ };
4459
+ /**
4460
+ * Custom JSON serialization that excludes getter properties
4461
+ */
4462
+ toJSON(): {
4463
+ _tag: "Left" | "Right";
4464
+ value: L | R;
4465
+ };
4466
+ }
4467
+ type TestEither<L extends Type, R extends Type> = Either<L, R> & AsyncMonad<R>;
4468
+ declare const Right: <L extends Type, R extends Type>(value: R) => Either<L, R>;
4469
+ declare const Left: <L extends Type, R extends Type>(value: L) => Either<L, R>;
4470
+ declare const isRight: <L extends Type, R extends Type>(either: Either<L, R>) => either is Either<L, R> & {
4471
+ value: R;
4472
+ };
4473
+ declare const isLeft: <L extends Type, R extends Type>(either: Either<L, R>) => either is Either<L, R> & {
4474
+ value: L;
4475
+ };
4476
+ declare const tryCatch: <L extends Type, R extends Type>(f: () => R, onError: (error: unknown) => L) => Either<L, R>;
4477
+ declare const TypeCheckRight: <L extends Type, R extends Type>(value: R) => TestEither<L, R>;
4478
+ declare const TypeCheckLeft: <L extends Type, R extends Type>(value: L) => TestEither<L, R>;
4479
+ declare const tryCatchAsync: <L extends Type, R extends Type>(f: () => Promise<R>, onError: (error: unknown) => L) => Promise<Either<L, R>>;
4480
+ declare const Either: (<L extends Type, R extends Type>(value: R | L, isRight: boolean) => Either<L, R>) & {
4481
+ /**
4482
+ * Creates a Left instance
4483
+ * @param value - The left value
4484
+ * @returns Left Either
4485
+ */
4486
+ left: <L extends Type, R extends Type>(value: L) => Either<L, R>;
4487
+ /**
4488
+ * Creates a Right instance
4489
+ * @param value - The right value
4490
+ * @returns Right Either
4491
+ */
4492
+ right: <L extends Type, R extends Type>(value: R) => Either<L, R>;
4493
+ /**
4494
+ * Type guard to check if an Either is Right
4495
+ * @param either - The Either to check
4496
+ * @returns True if Either is Right
4497
+ */
4498
+ isRight: <L extends Type, R extends Type>(either: Either<L, R>) => either is Either<L, R> & {
4499
+ value: R;
4500
+ };
4501
+ /**
4502
+ * Type guard to check if an Either is Left
4503
+ * @param either - The Either to check
4504
+ * @returns True if Either is Left
4505
+ */
4506
+ isLeft: <L extends Type, R extends Type>(either: Either<L, R>) => either is Either<L, R> & {
4507
+ value: L;
4508
+ };
4509
+ /**
4510
+ * Combines an array of Eithers into a single Either containing an array
4511
+ * @param eithers - Array of Either values
4512
+ * @returns Either with array of values or first Left encountered
4513
+ */
4514
+ sequence: <L extends Type, R extends Type>(eithers: Either<L, R>[]) => Either<L, R[]>;
4515
+ /**
4516
+ * Maps an array through a function that returns Either, then sequences the results
4517
+ * @param arr - Array of values
4518
+ * @param f - Function that returns Either
4519
+ * @returns Either with array of results or first Left encountered
4520
+ */
4521
+ traverse: <L extends Type, R extends Type, U extends Type>(arr: R[], f: (value: R) => Either<L, U>) => Either<L, U[]>;
4522
+ /**
4523
+ * Creates an Either from a nullable value
4524
+ * @param value - The value that might be null or undefined
4525
+ * @param leftValue - The value to use for Left if value is null/undefined
4526
+ * @returns Right if value is not null/undefined, Left otherwise
4527
+ */
4528
+ fromNullable: <L extends Type, R extends Type>(value: R | null | undefined, leftValue: L) => Either<L, R>;
4529
+ /**
4530
+ * Creates an Either based on a predicate
4531
+ * @param value - The value to test
4532
+ * @param predicate - The predicate function
4533
+ * @param leftValue - The value to use for Left if predicate fails
4534
+ * @returns Right if predicate passes, Left otherwise
4535
+ */
4536
+ fromPredicate: <L extends Type, R extends Type>(value: R, predicate: (value: R) => boolean, leftValue: L) => Either<L, R>;
4537
+ /**
4538
+ * Applicative apply - applies a wrapped function to a wrapped value
4539
+ * @param eitherF - Either containing a function
4540
+ * @param eitherV - Either containing a value
4541
+ * @returns Either with function applied to value
4542
+ */
4543
+ ap: <L extends Type, R extends Type, U extends Type>(eitherF: Either<L, (value: R) => U>, eitherV: Either<L, R>) => Either<L, U>;
4544
+ /**
4545
+ * Creates an Either from a Promise
4546
+ * @param promise - The Promise to convert
4547
+ * @param onRejected - Function to convert rejection reason to Left value
4548
+ * @returns Promise that resolves to Either
4549
+ */
4550
+ fromPromise: <L, R>(promise: Promise<R>, onRejected: (reason: unknown) => L) => Promise<Either<L, R>>;
4551
+ /**
4552
+ * Creates an Either from JSON string
4553
+ * @param json - The JSON string
4554
+ * @returns Either instance
4555
+ */
4556
+ fromJSON: <L extends Type, R extends Type>(json: string) => Either<L, R>;
4557
+ /**
4558
+ * Creates an Either from YAML string
4559
+ * @param yaml - The YAML string
4560
+ * @returns Either instance
4561
+ */
4562
+ fromYAML: <L extends Type, R extends Type>(yaml: string) => Either<L, R>;
4563
+ /**
4564
+ * Creates an Either from binary string
4565
+ * @param binary - The binary string
4566
+ * @returns Either instance
4567
+ */
4568
+ fromBinary: <L extends Type, R extends Type>(binary: string) => Either<L, R>;
4569
+ };
4570
+ //#endregion
4571
+ //#region src/do/index.d.ts
4572
+ type OptionLike = {
4573
+ _tag: "Some" | "None";
4574
+ isSome(): boolean;
4575
+ get(): unknown;
4576
+ };
4577
+ type EitherLike = {
4578
+ _tag: "Left" | "Right";
4579
+ isLeft(): boolean;
4580
+ isRight(): boolean;
4581
+ value: unknown;
4582
+ };
4583
+ type ListLike = {
4584
+ _tag: "List";
4585
+ toArray(): unknown[];
4586
+ };
4587
+ type TryLike = {
4588
+ _tag: "Success" | "Failure";
4589
+ isSuccess(): boolean;
4590
+ get(): unknown;
4591
+ };
4592
+ /**
4593
+ * Executes a generator-based monadic comprehension
4594
+ * Returns the same monad type as the first yielded monad (Scala semantics)
4595
+ *
4596
+ * - Option comprehensions return Option (None on short-circuit)
4597
+ * - Either comprehensions return Either (Left with error on short-circuit)
4598
+ * - List comprehensions return List (empty or cartesian product)
4599
+ * - Try comprehensions return Try (Failure with error on short-circuit)
4600
+ *
4601
+ * Type Inference Notes:
4602
+ * - TypeScript infers the correct return type for homogeneous comprehensions
4603
+ * - For mixed monad types, TypeScript returns a union type
4604
+ * - Use DoTyped<T> or type assertions for mixed scenarios
4605
+ *
4606
+ * @example
4607
+ * ```typescript
4608
+ * // Option comprehension returns Option:
4609
+ * const result = Do(function* () {
4610
+ * const x = yield* $(Option(5));
4611
+ * const y = yield* $(Option(10));
4612
+ * return x + y;
4613
+ * });
4614
+ * // result: Option(15)
4615
+ *
4616
+ * // Either comprehension returns Either:
4617
+ * const result = Do(function* () {
4618
+ * const x = yield* $(Right(5));
4619
+ * const y = yield* $(Left("error"));
4620
+ * return x + y;
4621
+ * });
4622
+ * // result: Left("error") - error is preserved
4623
+ *
4624
+ * // List comprehension returns List with cartesian product:
4625
+ * const result = Do(function* () {
4626
+ * const x = yield* $(List([1, 2]));
4627
+ * const y = yield* $(List([3, 4]));
4628
+ * return x + y;
4629
+ * });
4630
+ * // result: List([4, 5, 5, 6])
4631
+ *
4632
+ * // Mixed types - use type assertion or DoTyped:
4633
+ * const result = Do(function* () {
4634
+ * const x = yield* $(Option(5));
4635
+ * const y = yield* $(Right<string, number>(10));
4636
+ * return x + y;
4637
+ * }) as Option<number>;
4638
+ * // result: Option(15)
4639
+ * ```
4640
+ *
4641
+ * @param gen - Generator function that yields monads and returns a result
4642
+ * @returns The same monad type as the first yield
4643
+ */
4644
+ declare function Do<T>(gen: () => Generator<OptionLike, T, unknown>): Option<T>;
4645
+ declare function Do<L, R>(gen: () => Generator<EitherLike, R, unknown>): Either<L, R>;
4646
+ declare function Do<T>(gen: () => Generator<ListLike, T, unknown>): List<T>;
4647
+ declare function Do<T>(gen: () => Generator<TryLike, T, unknown>): Try<T>;
4648
+ declare function Do<T>(gen: () => Generator<OptionLike | EitherLike | ListLike | TryLike, T, unknown>): Reshapeable<T>;
4649
+ declare function Do<T>(gen: () => Generator<unknown, T, unknown>): unknown;
4650
+ /**
4651
+ * Executes an async generator-based monadic comprehension
4652
+ * Returns the same monad type as the first yielded monad
4653
+ *
4654
+ * @example
4655
+ * ```typescript
4656
+ * const result = await DoAsync(async function* () {
4657
+ * const user = yield* $(await fetchUser(id)); // Promise<Option<User>> → User
4658
+ * const profile = yield* $(await getProfile(user)); // Promise<Either<Error, Profile>> → Profile
4659
+ * return { user, profile };
4660
+ * });
4661
+ * // result type matches first yield
4662
+ * ```
4663
+ *
4664
+ * @param gen - Async generator function that yields monads/promises and returns a result
4665
+ * @returns Promise of the same monad type as first yield
4666
+ */
4667
+ declare function DoAsync<T>(gen: () => AsyncGenerator<OptionLike, T, unknown>): Promise<Option<T>>;
4668
+ declare function DoAsync<L, R>(gen: () => AsyncGenerator<EitherLike, R, unknown>): Promise<Either<L, R>>;
4669
+ declare function DoAsync<T>(gen: () => AsyncGenerator<ListLike, T, unknown>): Promise<List<T>>;
4670
+ declare function DoAsync<T>(gen: () => AsyncGenerator<TryLike, T, unknown>): Promise<Try<T>>;
4671
+ declare function DoAsync<T>(gen: () => AsyncGenerator<OptionLike | EitherLike | ListLike | TryLike, T, unknown>): Promise<Reshapeable<T>>;
4672
+ declare function DoAsync<T>(gen: () => AsyncGenerator<unknown, T, unknown>): Promise<unknown>;
4673
+ /**
4674
+ * Helper function to check if a value implements the Doable interface
4675
+ * @param value - Value to check
4676
+ * @returns True if the value implements Doable
4677
+ */
4678
+ declare function isDoCapable<T>(value: unknown): value is Doable<T>;
4679
+ /**
4680
+ * Manually unwrap a monad using the Doable interface
4681
+ * Useful for testing or when you need to unwrap outside of a Do-comprehension
4682
+ *
4683
+ * @param monad - Monad to unwrap
4684
+ * @returns The unwrapped value
4685
+ * @throws Error if the monad cannot be unwrapped
4686
+ */
4687
+ declare function unwrap<T>(monad: Doable<T>): T;
4688
+ /**
4689
+ * Type helper for Do-notation generators.
4690
+ * Provides better type hints in IDEs.
4691
+ *
4692
+ * @example
4693
+ * ```typescript
4694
+ * const result = Do(function* (): DoGenerator<number> {
4695
+ * const x = yield* $(List([1, 2])) // x is still unknown but return type is clear
4696
+ * const y = yield* $(List([3, 4]))
4697
+ * return x + y
4698
+ * })
4699
+ * ```
4700
+ */
4701
+ type DoGenerator<T, TYield = unknown> = Generator<TYield, T, unknown>;
4702
+ /**
4703
+ * Extracts values from monads in Do-notation with type inference.
4704
+ * The '$' symbol is the universal extraction operator in functional programming.
4705
+ *
4706
+ * @example
4707
+ * ```typescript
4708
+ * const result = Do(function* () {
4709
+ * const x = yield* $(Option(5)) // x: number
4710
+ * const y = yield* $(List([1, 2, 3])) // y: number (for cartesian product)
4711
+ * const name = yield* $(Right("Alice")) // name: string
4712
+ * return `${name}: ${x + y}`
4713
+ * })
4714
+ * ```
4715
+ *
4716
+ * @param monad - Any monad that can be unwrapped (Option, Either, List, Try, etc.)
4717
+ * @returns A generator that yields the monad and returns its extracted value
4718
+ */
4719
+ declare function $<T>(monad: Option<T>): Generator<Option<T>, T, T>;
4720
+ declare function $<L, R>(monad: Either<L, R>): Generator<Either<L, R>, R, R>;
4721
+ declare function $<T>(monad: List<T>): Generator<List<T>, T, T>;
4722
+ declare function $<T>(monad: Try<T>): Generator<Try<T>, T, T>;
4723
+ declare function $<T>(monad: Doable<T>): Generator<Doable<T>, T, T>;
4724
+ declare function $<M>(monad: M): Generator<M, InferYieldType<M>, InferYieldType<M>>;
4725
+ type InferYieldType<M> = M extends {
4726
+ isSome(): boolean;
4727
+ get(): infer T;
4728
+ } ? T : M extends {
4729
+ isRight(): boolean;
4730
+ value: infer R;
4731
+ } ? R : M extends {
4732
+ toArray(): (infer T)[];
4733
+ } ? T : M extends {
4734
+ isSuccess(): boolean;
4735
+ get(): infer T;
4736
+ } ? T : M extends Doable<infer T> ? T : unknown;
4737
+ declare const NoneError: (message?: string) => Error;
4738
+ interface LeftErrorType<L> extends Error {
4739
+ value: L;
4740
+ }
4741
+ declare const LeftError: <L>(value: L, message?: string) => LeftErrorType<L>;
4742
+ declare const EmptyListError: (message?: string) => Error;
4743
+ interface FailureErrorType extends Error {
4744
+ cause: Error;
4745
+ }
4746
+ declare const FailureError: (cause: Error, message?: string) => FailureErrorType;
4747
+ //#endregion
4748
+ export { TestClockTag as $, TaskFailure as $t, OptionConstructor as A, ValidatedBrand as An, ValidationRule as At, fromBinary as B, ContainerOps as Bn, TaskErrorInfo as Bt, Functype as C, NonEmptyString as Cn, OptionKind as Ct, List as D, PositiveNumber as Dn, FieldValidation as Dt, Collection as E, PositiveInteger as En, FoldableUtils as Et, Set as F, Applicative as Fn, TypedError as Ft, MatchableUtils as G, Doable as Gn, Async as Gt, fromYAML as H, Extractable as Hn, formatError as Ht, SerializationResult as I, AsyncMonad as In, TypedErrorContext as It, Map$1 as J, Err as Jt, ESMap as K, ParseError as Kn, CancellationToken as Kt, createCustomSerializer as L, Functor as Ln, ErrorChainElement as Lt, Stack as M, Try as Mn, ErrorCode as Mt, Valuable as N, TypeNames as Nn, ErrorMessage as Nt, None as O, UUID as On, FormValidation as Ot, ValuableParams as P, Promisable as Pn, ErrorStatus as Pt, TestClock as Q, Task$1 as Qt, createSerializationCompanion as R, Monad as Rn, ErrorFormatterOptions as Rt, tryCatchAsync as S, IntegerNumber as Sn, ListKind as St, FunctypeCollection as T, PatternString as Tn, UniversalContainer as Tt, Ref as U, isExtractable as Un, formatStackTrace as Ut, fromJSON as V, LazyList as Vn, createErrorSerializer as Vt, Matchable as W, DoResult as Wn, safeStringify as Wt, Traversable as X, Sync as Xt, SafeTraversable as Y, Ok as Yt, Lazy as Z, TaggedThrowable as Zt, TypeCheckLeft as _, Companion as _n, TagService as _t, EmptyListError as a, createCancellationTokenSource as an, TimeoutError as at, isRight as b, EmailAddress as bn, HKT as bt, LeftError as c, Throwable as cn, LayerError as ct, isDoCapable as d, Match as dn, Exit as dt, TaskMetadata as en, TestContext as et, unwrap as f, UntypedMatch as fn, ExitTag as ft, TestEither as g, isCompanion as gn, Tag as gt, Right as h, InstanceType as hn, HasService as ht, DoGenerator as i, TaskSuccess as in, Task as it, Some as j, ValidatedBrandCompanion as jn, Validator as jt, Option as k, UrlString as kn, Validation as kt, LeftErrorType as l, ThrowableType as ln, LayerInput as lt, Left as m, CompanionMethods as mn, ContextServices as mt, Do as n, TaskParams as nn, InterruptedError as nt, FailureError as o, isTaggedThrowable as on, UIO as ot, Either as p, Cond as pn, Context as pt, ESMapType as q, CancellationTokenSource as qt, DoAsync as r, TaskResult as rn, RIO as rt, FailureErrorType as s, NAME as sn, Layer as st, $ as t, TaskOutcome as tn, IO as tt, NoneError as u, Base as un, LayerOutput as ut, TypeCheckRight as v, BoundedNumber as vn, Identity as vt, FunctypeBase as w, NonNegativeNumber as wn, TryKind as wt, tryCatch as x, ISO8601Date as xn, Kind as xt, isLeft as y, BoundedString as yn, EitherKind as yt, createSerializer as z, CollectionOps as zn, ErrorWithTaskInfo as zt };