functype 0.49.0 → 0.50.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.
- package/dist/Brand-BJIRbUKB.d.ts +54 -0
- package/dist/{Typeable-lfO2nRVW.d.ts → Tuple-DmywDCE9.d.ts} +75 -1
- package/dist/Tuple-eVwTSeSr.js +1 -0
- package/dist/branded/index.d.ts +1 -53
- package/dist/cli/exports.js +1 -1
- package/dist/cli/index.js +4 -4
- package/dist/do/index.d.ts +2 -184
- package/dist/do/index.js +1 -1
- package/dist/either/index.d.ts +1 -187
- package/dist/either/index.js +1 -2
- package/dist/{full-interfaces-DzRVS-A-.js → full-interfaces-DVRjnPWW.js} +13 -1
- package/dist/{Functype-rgysbeU6.d.ts → index-OdnROQtM.d.ts} +915 -8
- package/dist/index.d.ts +4 -12
- package/dist/index.js +1 -1
- package/dist/list/index.d.ts +1 -84
- package/dist/list/index.js +1 -2
- package/dist/map/index.d.ts +1 -72
- package/dist/map/index.js +1 -2
- package/dist/option/index.d.ts +1 -242
- package/dist/option/index.js +1 -2
- package/dist/set/index.d.ts +1 -53
- package/dist/set/index.js +1 -2
- package/dist/src-ByDeJzWj.js +19 -0
- package/dist/try/index.d.ts +1 -96
- package/dist/try/index.js +1 -2
- package/dist/tuple/index.d.ts +1 -76
- package/dist/tuple/index.js +1 -1
- package/package.json +7 -7
- package/dist/Valuable-GZAXcYok.js +0 -13
- package/dist/stringify-DepodSy0.js +0 -1
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import { Brand } from "./
|
|
2
|
-
import {
|
|
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-DmywDCE9.js";
|
|
8
3
|
|
|
9
4
|
//#region src/error/ParseError.d.ts
|
|
10
5
|
declare const ParseError: (message?: string) => Error & {
|
|
@@ -416,6 +411,126 @@ interface Promisable<A extends Type> {
|
|
|
416
411
|
toPromise(): Promise<A>;
|
|
417
412
|
}
|
|
418
413
|
//#endregion
|
|
414
|
+
//#region src/try/Try.d.ts
|
|
415
|
+
/**
|
|
416
|
+
* Possible types of Try instances
|
|
417
|
+
*/
|
|
418
|
+
type TypeNames = "Success" | "Failure";
|
|
419
|
+
interface Try<T> extends FunctypeBase<T, TypeNames>, Extractable<T>, Pipe<T>, Promisable<T>, Doable<T>, Reshapeable<T> {
|
|
420
|
+
readonly _tag: TypeNames;
|
|
421
|
+
readonly error: Error | undefined;
|
|
422
|
+
isSuccess(): this is Try<T> & {
|
|
423
|
+
readonly _tag: "Success";
|
|
424
|
+
error: undefined;
|
|
425
|
+
};
|
|
426
|
+
isFailure(): this is Try<T> & {
|
|
427
|
+
readonly _tag: "Failure";
|
|
428
|
+
error: Error;
|
|
429
|
+
};
|
|
430
|
+
orElse: (defaultValue: T) => T;
|
|
431
|
+
orThrow: (error?: Error) => T;
|
|
432
|
+
or: (alternative: Try<T>) => Try<T>;
|
|
433
|
+
orNull: () => T | null;
|
|
434
|
+
orUndefined: () => T | undefined;
|
|
435
|
+
toOption: () => Option<T>;
|
|
436
|
+
toEither: <E extends Type>(leftValue: E) => Either<E, T>;
|
|
437
|
+
toList: () => List<T>;
|
|
438
|
+
toTry: () => Try<T>;
|
|
439
|
+
map: <U>(f: (value: T) => U) => Try<U>;
|
|
440
|
+
ap: <U>(ff: Try<(value: T) => U>) => Try<U>;
|
|
441
|
+
flatMap: <U>(f: (value: T) => Try<U>) => Try<U>;
|
|
442
|
+
flatMapAsync: <U>(f: (value: T) => Promise<Try<U>>) => Promise<Try<U>>;
|
|
443
|
+
/**
|
|
444
|
+
* Pattern matches over the Try, applying onFailure if Failure and onSuccess if Success
|
|
445
|
+
* @param onFailure - Function to apply if the Try is Failure
|
|
446
|
+
* @param onSuccess - Function to apply if the Try is Success
|
|
447
|
+
* @returns The result of applying the appropriate function
|
|
448
|
+
*/
|
|
449
|
+
fold: <U extends Type>(onFailure: (error: Error) => U, onSuccess: (value: T) => U) => U;
|
|
450
|
+
toString: () => string;
|
|
451
|
+
/**
|
|
452
|
+
* Pattern matches over the Try, applying a handler function based on the variant
|
|
453
|
+
* @param patterns - Object with handler functions for Success and Failure variants
|
|
454
|
+
* @returns The result of applying the matching handler function
|
|
455
|
+
*/
|
|
456
|
+
match<R>(patterns: {
|
|
457
|
+
Success: (value: T) => R;
|
|
458
|
+
Failure: (error: Error) => R;
|
|
459
|
+
}): R;
|
|
460
|
+
/**
|
|
461
|
+
* Recovers from a Failure by applying a function to the error, returning a new Try
|
|
462
|
+
* @param f - Function to apply to the error to produce a recovery value
|
|
463
|
+
* @returns Success with the recovery value if Failure, otherwise this
|
|
464
|
+
*/
|
|
465
|
+
recover: (f: (error: Error) => T) => Try<T>;
|
|
466
|
+
/**
|
|
467
|
+
* Recovers from a Failure by applying a function that returns a new Try
|
|
468
|
+
* @param f - Function to apply to the error to produce a new Try
|
|
469
|
+
* @returns The result of f if Failure, otherwise this
|
|
470
|
+
*/
|
|
471
|
+
recoverWith: (f: (error: Error) => Try<T>) => Try<T>;
|
|
472
|
+
toValue(): {
|
|
473
|
+
_tag: TypeNames;
|
|
474
|
+
value: T | Error;
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
declare const Try: (<T>(f: () => T) => Try<T>) & {
|
|
478
|
+
/**
|
|
479
|
+
* Creates a Success directly without needing a callback
|
|
480
|
+
* @param value - The success value
|
|
481
|
+
* @returns Try containing the value as Success
|
|
482
|
+
*/
|
|
483
|
+
success: <T>(value: T) => Try<T>;
|
|
484
|
+
/**
|
|
485
|
+
* Creates a Failure directly without needing to throw
|
|
486
|
+
* @param error - The error (string or Error instance)
|
|
487
|
+
* @returns Try containing the error as Failure
|
|
488
|
+
*/
|
|
489
|
+
failure: <T>(error: Error | string) => Try<T>;
|
|
490
|
+
/**
|
|
491
|
+
* Creates a Try from a Promise, resolving to Success or Failure
|
|
492
|
+
* @param promise - The promise to convert
|
|
493
|
+
* @returns Promise resolving to a Try
|
|
494
|
+
*/
|
|
495
|
+
fromPromise: <T>(promise: Promise<T>) => Promise<Try<T>>;
|
|
496
|
+
/**
|
|
497
|
+
* Type guard to check if a Try is Success
|
|
498
|
+
* @param tryValue - The Try to check
|
|
499
|
+
* @returns True if Try is Success
|
|
500
|
+
*/
|
|
501
|
+
isSuccess: <T>(tryValue: Try<T>) => tryValue is Try<T> & {
|
|
502
|
+
readonly _tag: "Success";
|
|
503
|
+
error: undefined;
|
|
504
|
+
};
|
|
505
|
+
/**
|
|
506
|
+
* Type guard to check if a Try is Failure
|
|
507
|
+
* @param tryValue - The Try to check
|
|
508
|
+
* @returns True if Try is Failure
|
|
509
|
+
*/
|
|
510
|
+
isFailure: <T>(tryValue: Try<T>) => tryValue is Try<T> & {
|
|
511
|
+
readonly _tag: "Failure";
|
|
512
|
+
error: Error;
|
|
513
|
+
};
|
|
514
|
+
/**
|
|
515
|
+
* Creates a Try from JSON string
|
|
516
|
+
* @param json - The JSON string
|
|
517
|
+
* @returns Try instance
|
|
518
|
+
*/
|
|
519
|
+
fromJSON: <T>(json: string) => Try<T>;
|
|
520
|
+
/**
|
|
521
|
+
* Creates a Try from YAML string
|
|
522
|
+
* @param yaml - The YAML string
|
|
523
|
+
* @returns Try instance
|
|
524
|
+
*/
|
|
525
|
+
fromYAML: <T>(yaml: string) => Try<T>;
|
|
526
|
+
/**
|
|
527
|
+
* Creates a Try from binary string
|
|
528
|
+
* @param binary - The binary string
|
|
529
|
+
* @returns Try instance
|
|
530
|
+
*/
|
|
531
|
+
fromBinary: <T>(binary: string) => Try<T>;
|
|
532
|
+
};
|
|
533
|
+
//#endregion
|
|
419
534
|
//#region src/reshapeable/Reshapeable.d.ts
|
|
420
535
|
/**
|
|
421
536
|
* Interface for types that can be reshaped (converted) between different monadic containers.
|
|
@@ -3435,6 +3550,73 @@ interface Traversable<A extends Type> extends AsyncMonad<A> {
|
|
|
3435
3550
|
reduceRight(f: (b: A, a: A) => A): A;
|
|
3436
3551
|
}
|
|
3437
3552
|
//#endregion
|
|
3553
|
+
//#region src/map/Map.d.ts
|
|
3554
|
+
/**
|
|
3555
|
+
* A traversable interface for map that excludes map and flatMap operations
|
|
3556
|
+
*/
|
|
3557
|
+
type SafeTraversable<K, V> = Omit<Traversable<Tuple<[K, V]>>, "map" | "flatMap" | "flatMapAsync" | "ap">;
|
|
3558
|
+
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]> {
|
|
3559
|
+
readonly [Symbol.toStringTag]: string;
|
|
3560
|
+
readonly _tag: "Map";
|
|
3561
|
+
add(item: Tuple<[K, V]>): Map$1<K, V>;
|
|
3562
|
+
remove(value: K): Map$1<K, V>;
|
|
3563
|
+
map<U>(f: (value: V) => U): Map$1<K, U>;
|
|
3564
|
+
ap<U>(ff: Map$1<K, (value: V) => U>): Map$1<K, U>;
|
|
3565
|
+
flatMap<K2, V2>(f: (entry: Tuple<[K, V]>) => Iterable<[K2, V2]>): Map$1<K2, V2>;
|
|
3566
|
+
flatMapAsync<U>(f: (value: V) => PromiseLike<Map$1<K, U>>): PromiseLike<Map$1<K, U>>;
|
|
3567
|
+
get(key: K): Option<V>;
|
|
3568
|
+
getOrElse(key: K, defaultValue: V): V;
|
|
3569
|
+
orElse(key: K, alternative: Option<V>): Option<V>;
|
|
3570
|
+
fold<U extends Type>(onEmpty: () => U, onValue: (value: Tuple<[K, V]>) => U): U;
|
|
3571
|
+
foldLeft<B>(z: B): (op: (b: B, a: Tuple<[K, V]>) => B) => B;
|
|
3572
|
+
foldRight<B>(z: B): (op: (a: Tuple<[K, V]>, b: B) => B) => B;
|
|
3573
|
+
/**
|
|
3574
|
+
* Pattern matches over the Map, applying a handler function based on whether it's empty
|
|
3575
|
+
* @param patterns - Object with handler functions for Empty and NonEmpty variants
|
|
3576
|
+
* @returns The result of applying the matching handler function
|
|
3577
|
+
*/
|
|
3578
|
+
match<R>(patterns: {
|
|
3579
|
+
Empty: () => R;
|
|
3580
|
+
NonEmpty: (entries: Array<Tuple<[K, V]>>) => R;
|
|
3581
|
+
}): R;
|
|
3582
|
+
toValue(): {
|
|
3583
|
+
_tag: "Map";
|
|
3584
|
+
value: [K, V][];
|
|
3585
|
+
};
|
|
3586
|
+
}
|
|
3587
|
+
declare const Map$1: (<K, V>(entries?: readonly (readonly [K, V])[] | IterableIterator<[K, V]> | null) => Map$1<K, V>) & {
|
|
3588
|
+
/**
|
|
3589
|
+
* Creates an empty Map
|
|
3590
|
+
* Returns a singleton instance for efficiency
|
|
3591
|
+
* @returns An empty Map instance
|
|
3592
|
+
*/
|
|
3593
|
+
empty: <K, V>() => Map$1<K, V>;
|
|
3594
|
+
/**
|
|
3595
|
+
* Creates a Map from variadic key-value pair arguments
|
|
3596
|
+
* @param entries - Key-value pairs to create map from
|
|
3597
|
+
* @returns A Map containing the entries
|
|
3598
|
+
*/
|
|
3599
|
+
of: <K, V>(...entries: [K, V][]) => Map$1<K, V>;
|
|
3600
|
+
/**
|
|
3601
|
+
* Creates a Map from JSON string
|
|
3602
|
+
* @param json - The JSON string
|
|
3603
|
+
* @returns Map instance
|
|
3604
|
+
*/
|
|
3605
|
+
fromJSON: <K, V>(json: string) => Map$1<K, V>;
|
|
3606
|
+
/**
|
|
3607
|
+
* Creates a Map from YAML string
|
|
3608
|
+
* @param yaml - The YAML string
|
|
3609
|
+
* @returns Map instance
|
|
3610
|
+
*/
|
|
3611
|
+
fromYAML: <K, V>(yaml: string) => Map$1<K, V>;
|
|
3612
|
+
/**
|
|
3613
|
+
* Creates a Map from binary string
|
|
3614
|
+
* @param binary - The binary string
|
|
3615
|
+
* @returns Map instance
|
|
3616
|
+
*/
|
|
3617
|
+
fromBinary: <K, V>(binary: string) => Map$1<K, V>;
|
|
3618
|
+
};
|
|
3619
|
+
//#endregion
|
|
3438
3620
|
//#region src/map/shim.d.ts
|
|
3439
3621
|
/**
|
|
3440
3622
|
* Type alias for the native JavaScript Map
|
|
@@ -3615,6 +3797,55 @@ declare const createSerializationCompanion: <T>(reconstructor: (parsed: {
|
|
|
3615
3797
|
fromBinary: (binary: string) => T;
|
|
3616
3798
|
};
|
|
3617
3799
|
//#endregion
|
|
3800
|
+
//#region src/set/Set.d.ts
|
|
3801
|
+
interface Set<A> extends FunctypeCollection<A, "Set">, Collection<A> {
|
|
3802
|
+
add: (value: A) => Set<A>;
|
|
3803
|
+
remove: (value: A) => Set<A>;
|
|
3804
|
+
contains: (value: A) => boolean;
|
|
3805
|
+
has: (value: A) => boolean;
|
|
3806
|
+
map: <B>(f: (a: A) => B) => Set<B>;
|
|
3807
|
+
flatMap: <B>(f: (a: A) => Iterable<B>) => Set<B>;
|
|
3808
|
+
filter: (p: (a: A) => boolean) => Set<A>;
|
|
3809
|
+
filterNot: (p: (a: A) => boolean) => Set<A>;
|
|
3810
|
+
fold: <U extends Type>(onEmpty: () => U, onValue: (value: A) => U) => U;
|
|
3811
|
+
toList: () => List<A>;
|
|
3812
|
+
toSet: () => Set<A>;
|
|
3813
|
+
toArray: <B = A>() => B[];
|
|
3814
|
+
toString: () => string;
|
|
3815
|
+
}
|
|
3816
|
+
declare const Set: (<A>(iterable?: Iterable<A>) => Set<A>) & {
|
|
3817
|
+
/**
|
|
3818
|
+
* Creates an empty Set
|
|
3819
|
+
* Returns a singleton instance for efficiency
|
|
3820
|
+
* @returns An empty Set instance
|
|
3821
|
+
*/
|
|
3822
|
+
empty: <A extends Type>() => Set<A>;
|
|
3823
|
+
/**
|
|
3824
|
+
* Creates a Set from variadic arguments
|
|
3825
|
+
* @param values - Values to create set from
|
|
3826
|
+
* @returns A Set containing the unique values
|
|
3827
|
+
*/
|
|
3828
|
+
of: <A extends Type>(...values: A[]) => Set<A>;
|
|
3829
|
+
/**
|
|
3830
|
+
* Creates a Set from JSON string
|
|
3831
|
+
* @param json - The JSON string
|
|
3832
|
+
* @returns Set instance
|
|
3833
|
+
*/
|
|
3834
|
+
fromJSON: <A>(json: string) => Set<A>;
|
|
3835
|
+
/**
|
|
3836
|
+
* Creates a Set from YAML string
|
|
3837
|
+
* @param yaml - The YAML string
|
|
3838
|
+
* @returns Set instance
|
|
3839
|
+
*/
|
|
3840
|
+
fromYAML: <A>(yaml: string) => Set<A>;
|
|
3841
|
+
/**
|
|
3842
|
+
* Creates a Set from binary string
|
|
3843
|
+
* @param binary - The binary string
|
|
3844
|
+
* @returns Set instance
|
|
3845
|
+
*/
|
|
3846
|
+
fromBinary: <A>(binary: string) => Set<A>;
|
|
3847
|
+
};
|
|
3848
|
+
//#endregion
|
|
3618
3849
|
//#region src/valuable/Valuable.d.ts
|
|
3619
3850
|
/**
|
|
3620
3851
|
* Parameters for creating a Valuable instance
|
|
@@ -3748,6 +3979,323 @@ declare const Stack: (<A extends Type>(values?: A[]) => Stack<A>) & {
|
|
|
3748
3979
|
fromBinary: <A>(binary: string) => Stack<A>;
|
|
3749
3980
|
};
|
|
3750
3981
|
//#endregion
|
|
3982
|
+
//#region src/option/Option.d.ts
|
|
3983
|
+
/**
|
|
3984
|
+
* Option type module
|
|
3985
|
+
* @module Option
|
|
3986
|
+
* @category Core
|
|
3987
|
+
*/
|
|
3988
|
+
/**
|
|
3989
|
+
* The Option type represents a value that may or may not exist.
|
|
3990
|
+
* It's used to handle potentially null or undefined values in a type-safe way.
|
|
3991
|
+
* @typeParam T - The type of the value contained in the Option
|
|
3992
|
+
*/
|
|
3993
|
+
interface Option<T extends Type> extends Functype<T, "Some" | "None">, Promisable<T>, Doable<T>, Reshapeable<T> {
|
|
3994
|
+
/** The contained value (undefined for None) */
|
|
3995
|
+
readonly value: T | undefined;
|
|
3996
|
+
/** Whether this Option contains no value */
|
|
3997
|
+
isEmpty: boolean;
|
|
3998
|
+
/**
|
|
3999
|
+
* Returns true if this Option is a Some (contains a value)
|
|
4000
|
+
* @returns true if this Option contains a value, false otherwise
|
|
4001
|
+
*/
|
|
4002
|
+
isSome(): this is Option<T> & {
|
|
4003
|
+
value: T;
|
|
4004
|
+
isEmpty: false;
|
|
4005
|
+
};
|
|
4006
|
+
/**
|
|
4007
|
+
* Returns true if this Option is a None (contains no value)
|
|
4008
|
+
* @returns true if this Option is empty, false otherwise
|
|
4009
|
+
*/
|
|
4010
|
+
isNone(): this is Option<T> & {
|
|
4011
|
+
value: undefined;
|
|
4012
|
+
isEmpty: true;
|
|
4013
|
+
};
|
|
4014
|
+
/**
|
|
4015
|
+
* Returns the contained value or a default value if None
|
|
4016
|
+
* @param defaultValue - The value to return if this Option is None
|
|
4017
|
+
* @returns The contained value or defaultValue
|
|
4018
|
+
*/
|
|
4019
|
+
orElse(defaultValue: T): T;
|
|
4020
|
+
/**
|
|
4021
|
+
* Returns the contained value or throws an error if None
|
|
4022
|
+
* @param error - Optional custom error to throw. If not provided, throws a default error
|
|
4023
|
+
* @returns The contained value
|
|
4024
|
+
* @throws The specified error or a default error if the Option is None
|
|
4025
|
+
*/
|
|
4026
|
+
orThrow(error?: Error): T;
|
|
4027
|
+
/**
|
|
4028
|
+
* Returns this Option if it contains a value, otherwise returns the alternative container
|
|
4029
|
+
* @param alternative - The alternative Option to return if this is None
|
|
4030
|
+
* @returns This Option or the alternative
|
|
4031
|
+
*/
|
|
4032
|
+
or(alternative: Option<T>): Option<T>;
|
|
4033
|
+
/**
|
|
4034
|
+
* Returns the contained value or null if None
|
|
4035
|
+
* @returns The contained value or null
|
|
4036
|
+
*/
|
|
4037
|
+
orNull(): T | null;
|
|
4038
|
+
/**
|
|
4039
|
+
* Returns the contained value or undefined if None
|
|
4040
|
+
* @returns The contained value or undefined
|
|
4041
|
+
*/
|
|
4042
|
+
orUndefined(): T | undefined;
|
|
4043
|
+
/**
|
|
4044
|
+
* Maps the value inside the Option using the provided function
|
|
4045
|
+
* @param f - The mapping function
|
|
4046
|
+
* @returns A new Option containing the mapped value, or None if this Option is None
|
|
4047
|
+
*/
|
|
4048
|
+
map<U extends Type>(f: (value: T) => U): Option<U>;
|
|
4049
|
+
/**
|
|
4050
|
+
* Applies a wrapped function to a wrapped value (Applicative pattern)
|
|
4051
|
+
* @param ff - An Option containing a function from T to U
|
|
4052
|
+
* @returns A new Option containing the result of applying the function
|
|
4053
|
+
*/
|
|
4054
|
+
ap<U extends Type>(ff: Option<(value: T) => U>): Option<U>;
|
|
4055
|
+
/**
|
|
4056
|
+
* Returns this Option if it contains a value that satisfies the predicate, otherwise returns None
|
|
4057
|
+
* @param predicate - The predicate function to test the value
|
|
4058
|
+
* @returns This Option or None
|
|
4059
|
+
*/
|
|
4060
|
+
filter(predicate: (value: T) => boolean): Option<T>;
|
|
4061
|
+
/**
|
|
4062
|
+
* Maps the value using a function that returns an Option
|
|
4063
|
+
* @param f - The mapping function returning an Option
|
|
4064
|
+
* @returns The result of applying f to the contained value, or None if this Option is None
|
|
4065
|
+
*/
|
|
4066
|
+
flatMap<U extends Type>(f: (value: T) => Option<U>): Option<U>;
|
|
4067
|
+
/**
|
|
4068
|
+
* Maps the value using an async function that returns an Option
|
|
4069
|
+
* @param f - The async mapping function returning an Option
|
|
4070
|
+
* @returns Promise of the result of applying f to the contained value, or None if this Option is None
|
|
4071
|
+
*/
|
|
4072
|
+
flatMapAsync<U extends Type>(f: (value: T) => Promise<Option<U>>): Promise<Option<U>>;
|
|
4073
|
+
/**
|
|
4074
|
+
* Applies a binary operator to a start value and the contained value
|
|
4075
|
+
* @param f - The binary operator
|
|
4076
|
+
* @returns The result of the reduction
|
|
4077
|
+
*/
|
|
4078
|
+
reduce<U>(f: (acc: U, value: T) => U): U;
|
|
4079
|
+
/**
|
|
4080
|
+
* Applies a binary operator to the contained value and a start value
|
|
4081
|
+
* @param f - The binary operator
|
|
4082
|
+
* @returns The result of the reduction
|
|
4083
|
+
*/
|
|
4084
|
+
reduceRight<U>(f: (acc: U, value: T) => U): U;
|
|
4085
|
+
/**
|
|
4086
|
+
* Pattern matches over the Option, applying onNone if None and onSome if Some
|
|
4087
|
+
* @param onNone - Function to apply if the Option is None
|
|
4088
|
+
* @param onSome - Function to apply if the Option has a value
|
|
4089
|
+
* @returns The result of applying the appropriate function
|
|
4090
|
+
*/
|
|
4091
|
+
fold<U>(onNone: () => U, onSome: (value: T) => U): U;
|
|
4092
|
+
/**
|
|
4093
|
+
* Left-associative fold using the provided zero value and operation
|
|
4094
|
+
* @param z - Zero/identity value
|
|
4095
|
+
* @returns A function that takes an operation to apply
|
|
4096
|
+
*/
|
|
4097
|
+
foldLeft<B>(z: B): (op: (b: B, a: T) => B) => B;
|
|
4098
|
+
/**
|
|
4099
|
+
* Right-associative fold using the provided zero value and operation
|
|
4100
|
+
* @param z - Zero/identity value
|
|
4101
|
+
* @returns A function that takes an operation to apply
|
|
4102
|
+
*/
|
|
4103
|
+
foldRight<B>(z: B): (op: (a: T, b: B) => B) => B;
|
|
4104
|
+
/**
|
|
4105
|
+
* Converts this Option to a List
|
|
4106
|
+
* @returns A List containing the value if Some, or empty List if None
|
|
4107
|
+
*/
|
|
4108
|
+
toList(): List<T>;
|
|
4109
|
+
/**
|
|
4110
|
+
* Checks if this Option contains the specified value
|
|
4111
|
+
* @param value - The value to check for
|
|
4112
|
+
* @returns true if this Option contains the value, false otherwise
|
|
4113
|
+
*/
|
|
4114
|
+
contains(value: T): boolean;
|
|
4115
|
+
/** The number of elements in this Option (0 or 1) */
|
|
4116
|
+
size: number;
|
|
4117
|
+
/**
|
|
4118
|
+
* Converts this Option to an Either
|
|
4119
|
+
* @param left - The value to use for Left if this Option is None
|
|
4120
|
+
* @returns Either.Right with the contained value if Some, or Either.Left with left if None
|
|
4121
|
+
*/
|
|
4122
|
+
toEither<E>(left: E): Either<E, T>;
|
|
4123
|
+
/**
|
|
4124
|
+
* Returns a string representation of this Option
|
|
4125
|
+
* @returns A string representation
|
|
4126
|
+
*/
|
|
4127
|
+
toString(): string;
|
|
4128
|
+
/**
|
|
4129
|
+
* Returns a simple object representation of this Option
|
|
4130
|
+
* @returns An object with _tag and value properties
|
|
4131
|
+
*/
|
|
4132
|
+
toValue(): {
|
|
4133
|
+
_tag: "Some" | "None";
|
|
4134
|
+
value: T;
|
|
4135
|
+
};
|
|
4136
|
+
/**
|
|
4137
|
+
* Pattern matches over the Option, applying a handler function based on the variant
|
|
4138
|
+
* @param patterns - Object with handler functions for Some and None variants
|
|
4139
|
+
* @returns The result of applying the matching handler function
|
|
4140
|
+
*/
|
|
4141
|
+
match<R>(patterns: {
|
|
4142
|
+
Some: (value: T) => R;
|
|
4143
|
+
None: () => R;
|
|
4144
|
+
}): R;
|
|
4145
|
+
}
|
|
4146
|
+
/**
|
|
4147
|
+
* Creates a Some variant of Option containing a value.
|
|
4148
|
+
* @param value - The value to wrap in Some
|
|
4149
|
+
* @returns A new Some instance containing the value
|
|
4150
|
+
* @typeParam T - The type of the value
|
|
4151
|
+
*/
|
|
4152
|
+
declare const Some: <T extends Type>(value: T) => Option<T>;
|
|
4153
|
+
/**
|
|
4154
|
+
* Creates a None variant of Option representing absence of a value.
|
|
4155
|
+
* @returns A new None instance
|
|
4156
|
+
* @typeParam T - The type that would be contained if this was a Some
|
|
4157
|
+
*/
|
|
4158
|
+
declare const None: <T extends Type>() => Option<T>;
|
|
4159
|
+
/**
|
|
4160
|
+
* Safely wraps a value that might be null or undefined in an Option.
|
|
4161
|
+
* Creates Some if the value is defined, None otherwise.
|
|
4162
|
+
* @param value - The value to wrap (might be null/undefined)
|
|
4163
|
+
* @returns Some(value) if value is defined, None otherwise
|
|
4164
|
+
* @typeParam T - The type of the value
|
|
4165
|
+
*/
|
|
4166
|
+
declare const OptionConstructor: <T extends Type>(value: T | null | undefined) => Option<T>;
|
|
4167
|
+
declare const Option: (<T extends Type>(value: T | null | undefined) => Option<T>) & {
|
|
4168
|
+
/**
|
|
4169
|
+
* Creates an Option from any value. Alias for Option function.
|
|
4170
|
+
* @param value - The value to wrap
|
|
4171
|
+
* @returns Some(value) if value is defined, None otherwise
|
|
4172
|
+
* @typeParam T - The type of the value
|
|
4173
|
+
*/
|
|
4174
|
+
from: <T>(value: T) => Option<T>;
|
|
4175
|
+
/**
|
|
4176
|
+
* Returns a None instance. Alias for None function.
|
|
4177
|
+
* @returns A None instance
|
|
4178
|
+
* @typeParam T - The type that would be contained if this was a Some
|
|
4179
|
+
*/
|
|
4180
|
+
none: <T>() => Option<T>;
|
|
4181
|
+
/**
|
|
4182
|
+
* Type guard to check if an Option is Some
|
|
4183
|
+
* @param option - The Option to check
|
|
4184
|
+
* @returns True if Option is Some
|
|
4185
|
+
*/
|
|
4186
|
+
isSome: <T>(option: Option<T>) => option is Option<T> & {
|
|
4187
|
+
value: T;
|
|
4188
|
+
isEmpty: false;
|
|
4189
|
+
};
|
|
4190
|
+
/**
|
|
4191
|
+
* Type guard to check if an Option is None
|
|
4192
|
+
* @param option - The Option to check
|
|
4193
|
+
* @returns True if Option is None
|
|
4194
|
+
*/
|
|
4195
|
+
isNone: <T>(option: Option<T>) => option is Option<T> & {
|
|
4196
|
+
value: undefined;
|
|
4197
|
+
isEmpty: true;
|
|
4198
|
+
};
|
|
4199
|
+
/**
|
|
4200
|
+
* Creates an Option from JSON string
|
|
4201
|
+
* @param json - The JSON string
|
|
4202
|
+
* @returns Option instance
|
|
4203
|
+
*/
|
|
4204
|
+
fromJSON: <T>(json: string) => Option<T>;
|
|
4205
|
+
/**
|
|
4206
|
+
* Creates an Option from YAML string
|
|
4207
|
+
* @param yaml - The YAML string
|
|
4208
|
+
* @returns Option instance
|
|
4209
|
+
*/
|
|
4210
|
+
fromYAML: <T>(yaml: string) => Option<T>;
|
|
4211
|
+
/**
|
|
4212
|
+
* Creates an Option from binary string
|
|
4213
|
+
* @param binary - The binary string
|
|
4214
|
+
* @returns Option instance
|
|
4215
|
+
*/
|
|
4216
|
+
fromBinary: <T>(binary: string) => Option<T>;
|
|
4217
|
+
};
|
|
4218
|
+
//#endregion
|
|
4219
|
+
//#region src/list/List.d.ts
|
|
4220
|
+
interface List<A> extends FunctypeCollection<A, "List">, Doable<A>, Reshapeable<A> {
|
|
4221
|
+
readonly length: number;
|
|
4222
|
+
readonly [Symbol.iterator]: () => Iterator<A>;
|
|
4223
|
+
map: <B>(f: (a: A) => B) => List<B>;
|
|
4224
|
+
ap: <B>(ff: List<(value: A) => B>) => List<B>;
|
|
4225
|
+
flatMap: <B>(f: (a: A) => Iterable<B>) => List<B>;
|
|
4226
|
+
flatMapAsync: <B>(f: (a: A) => PromiseLike<Iterable<B>>) => PromiseLike<List<B>>;
|
|
4227
|
+
filter<S extends A>(predicate: (a: A) => a is S): List<S>;
|
|
4228
|
+
filter(predicate: (a: A) => unknown): List<A>;
|
|
4229
|
+
filterNot: (p: (a: A) => boolean) => List<A>;
|
|
4230
|
+
/** @internal */
|
|
4231
|
+
filterType: <T extends Typeable<string, unknown>>(tag: string) => List<T & A>;
|
|
4232
|
+
remove: (value: A) => List<A>;
|
|
4233
|
+
removeAt: (index: number) => List<A>;
|
|
4234
|
+
add: (item: A) => List<A>;
|
|
4235
|
+
get: (index: number) => Option<A>;
|
|
4236
|
+
concat: (other: List<A>) => List<A>;
|
|
4237
|
+
take: (n: number) => List<A>;
|
|
4238
|
+
takeWhile: (p: (a: A) => boolean) => List<A>;
|
|
4239
|
+
takeRight: (n: number) => List<A>;
|
|
4240
|
+
get last(): A | undefined;
|
|
4241
|
+
get lastOption(): Option<A>;
|
|
4242
|
+
get tail(): List<A>;
|
|
4243
|
+
get init(): List<A>;
|
|
4244
|
+
reverse: () => List<A>;
|
|
4245
|
+
indexOf: (value: A) => number;
|
|
4246
|
+
prepend: (item: A) => List<A>;
|
|
4247
|
+
distinct: () => List<A>;
|
|
4248
|
+
sorted: (compareFn?: (a: A, b: A) => number) => List<A>;
|
|
4249
|
+
sortBy: <B>(f: (a: A) => B, compareFn?: (a: B, b: B) => number) => List<A>;
|
|
4250
|
+
zip: <B>(other: List<B>) => List<[A, B]>;
|
|
4251
|
+
zipWithIndex: () => List<[A, number]>;
|
|
4252
|
+
groupBy: <K>(f: (a: A) => K) => globalThis.Map<K, List<A>>;
|
|
4253
|
+
partition: (p: (a: A) => boolean) => [List<A>, List<A>];
|
|
4254
|
+
span: (p: (a: A) => boolean) => [List<A>, List<A>];
|
|
4255
|
+
slice: (start: number, end: number) => List<A>;
|
|
4256
|
+
/**
|
|
4257
|
+
* Pattern matches over the List, applying a handler function based on whether it's empty
|
|
4258
|
+
* @param patterns - Object with handler functions for Empty and NonEmpty variants
|
|
4259
|
+
* @returns The result of applying the matching handler function
|
|
4260
|
+
*/
|
|
4261
|
+
match<R>(patterns: {
|
|
4262
|
+
Empty: () => R;
|
|
4263
|
+
NonEmpty: (values: A[]) => R;
|
|
4264
|
+
}): R;
|
|
4265
|
+
}
|
|
4266
|
+
declare const List: (<A>(values?: Iterable<A>) => List<A>) & {
|
|
4267
|
+
/**
|
|
4268
|
+
* Creates an empty List
|
|
4269
|
+
* Returns a singleton instance for efficiency
|
|
4270
|
+
* @returns An empty List instance
|
|
4271
|
+
*/
|
|
4272
|
+
empty: <A extends Type>() => List<A>;
|
|
4273
|
+
/**
|
|
4274
|
+
* Creates a List from variadic arguments
|
|
4275
|
+
* @param values - Values to create list from
|
|
4276
|
+
* @returns A List containing the values
|
|
4277
|
+
*/
|
|
4278
|
+
of: <A extends Type>(...values: A[]) => List<A>;
|
|
4279
|
+
/**
|
|
4280
|
+
* Creates a List from JSON string
|
|
4281
|
+
* @param json - The JSON string
|
|
4282
|
+
* @returns List instance
|
|
4283
|
+
*/
|
|
4284
|
+
fromJSON: <A>(json: string) => List<A>;
|
|
4285
|
+
/**
|
|
4286
|
+
* Creates a List from YAML string
|
|
4287
|
+
* @param yaml - The YAML string
|
|
4288
|
+
* @returns List instance
|
|
4289
|
+
*/
|
|
4290
|
+
fromYAML: <A>(yaml: string) => List<A>;
|
|
4291
|
+
/**
|
|
4292
|
+
* Creates a List from binary string
|
|
4293
|
+
* @param binary - The binary string
|
|
4294
|
+
* @returns List instance
|
|
4295
|
+
*/
|
|
4296
|
+
fromBinary: <A>(binary: string) => List<A>;
|
|
4297
|
+
};
|
|
4298
|
+
//#endregion
|
|
3751
4299
|
//#region src/collections/index.d.ts
|
|
3752
4300
|
/**
|
|
3753
4301
|
* Represents a collection with conversion capabilities
|
|
@@ -3810,4 +4358,363 @@ interface FunctypeCollection<A, Tag extends string = string> extends Omit<Functy
|
|
|
3810
4358
|
flatMapAsync<B extends Type>(f: (value: A) => PromiseLike<Iterable<B>>): PromiseLike<FunctypeCollection<B, Tag>>;
|
|
3811
4359
|
}
|
|
3812
4360
|
//#endregion
|
|
3813
|
-
|
|
4361
|
+
//#region src/either/Either.d.ts
|
|
4362
|
+
/**
|
|
4363
|
+
* Either type module
|
|
4364
|
+
* @module Either
|
|
4365
|
+
* @category Core
|
|
4366
|
+
*/
|
|
4367
|
+
interface Either<L extends Type, R extends Type> extends FunctypeBase<R, "Left" | "Right">, Promisable<R>, Doable<R>, Reshapeable<R>, Extractable<R> {
|
|
4368
|
+
readonly _tag: "Left" | "Right";
|
|
4369
|
+
value: L | R;
|
|
4370
|
+
isLeft(): this is Either<L, R> & {
|
|
4371
|
+
readonly _tag: "Left";
|
|
4372
|
+
value: L;
|
|
4373
|
+
};
|
|
4374
|
+
isRight(): this is Either<L, R> & {
|
|
4375
|
+
readonly _tag: "Right";
|
|
4376
|
+
value: R;
|
|
4377
|
+
};
|
|
4378
|
+
orElse: (defaultValue: R) => R;
|
|
4379
|
+
orThrow: (error?: Error) => R;
|
|
4380
|
+
or(alternative: Either<L, R>): Either<L, R>;
|
|
4381
|
+
orNull: () => R | null;
|
|
4382
|
+
orUndefined: () => R | undefined;
|
|
4383
|
+
readonly map: <U extends Type>(f: (value: R) => U) => Either<L, U>;
|
|
4384
|
+
ap: <U extends Type>(ff: Either<L, (value: R) => U>) => Either<L, U>;
|
|
4385
|
+
merge: <L1 extends Type, R1 extends Type>(other: Either<L1, R1>) => Either<L | L1, [R, R1]>;
|
|
4386
|
+
mapAsync: <U extends Type>(f: (value: R) => Promise<U>) => Promise<Either<L, U>>;
|
|
4387
|
+
flatMap: <U extends Type>(f: (value: R) => Either<L, U>) => Either<L, U>;
|
|
4388
|
+
flatMapAsync: <U extends Type>(f: (value: R) => Promise<Either<L, U>>) => Promise<Either<L, U>>;
|
|
4389
|
+
toOption: () => Option<R>;
|
|
4390
|
+
toList: () => List<R>;
|
|
4391
|
+
toString: () => string;
|
|
4392
|
+
[Symbol.iterator]: () => Iterator<R>;
|
|
4393
|
+
yield: () => Generator<R, void, unknown>;
|
|
4394
|
+
traverse: <U extends Type>(f: (value: R) => Either<L, U>) => Either<L, U[]>;
|
|
4395
|
+
lazyMap: <U extends Type>(f: (value: R) => U) => Generator<Either<L, U>, void, unknown>;
|
|
4396
|
+
tap: (f: (value: R) => void) => Either<L, R>;
|
|
4397
|
+
tapLeft: (f: (value: L) => void) => Either<L, R>;
|
|
4398
|
+
mapLeft: <L2 extends Type>(f: (value: L) => L2) => Either<L2, R>;
|
|
4399
|
+
bimap: <L2 extends Type, R2 extends Type>(fl: (value: L) => L2, fr: (value: R) => R2) => Either<L2, R2>;
|
|
4400
|
+
fold: <T extends Type>(onLeft: (value: L) => T, onRight: (value: R) => T) => T;
|
|
4401
|
+
swap: () => Either<R, L>;
|
|
4402
|
+
/**
|
|
4403
|
+
* Pipes the value through the provided function based on whether this is a Left or Right
|
|
4404
|
+
* @param onLeft - The function to apply if this is a Left
|
|
4405
|
+
* @param onRight - The function to apply if this is a Right
|
|
4406
|
+
* @returns The result of applying the appropriate function
|
|
4407
|
+
*/
|
|
4408
|
+
pipeEither<U extends Type>(onLeft: (value: L) => U, onRight: (value: R) => U): U;
|
|
4409
|
+
/**
|
|
4410
|
+
* Pipes the Either value through the provided function
|
|
4411
|
+
* @param f - The function to apply to the value (Left or Right)
|
|
4412
|
+
* @returns The result of applying the function to the value
|
|
4413
|
+
*/
|
|
4414
|
+
pipe<U extends Type>(f: (value: L | R) => U): U;
|
|
4415
|
+
/**
|
|
4416
|
+
* Pattern matches over the Either, applying a handler function based on the variant
|
|
4417
|
+
* @param patterns - Object with handler functions for Left and Right variants
|
|
4418
|
+
* @returns The result of applying the matching handler function
|
|
4419
|
+
*/
|
|
4420
|
+
match<T>(patterns: {
|
|
4421
|
+
Left: (value: L) => T;
|
|
4422
|
+
Right: (value: R) => T;
|
|
4423
|
+
}): T;
|
|
4424
|
+
/**
|
|
4425
|
+
* Returns the value and tag for inspection
|
|
4426
|
+
*/
|
|
4427
|
+
toValue(): {
|
|
4428
|
+
_tag: "Left" | "Right";
|
|
4429
|
+
value: L | R;
|
|
4430
|
+
};
|
|
4431
|
+
/**
|
|
4432
|
+
* Custom JSON serialization that excludes getter properties
|
|
4433
|
+
*/
|
|
4434
|
+
toJSON(): {
|
|
4435
|
+
_tag: "Left" | "Right";
|
|
4436
|
+
value: L | R;
|
|
4437
|
+
};
|
|
4438
|
+
}
|
|
4439
|
+
type TestEither<L extends Type, R extends Type> = Either<L, R> & AsyncMonad<R>;
|
|
4440
|
+
declare const Right: <L extends Type, R extends Type>(value: R) => Either<L, R>;
|
|
4441
|
+
declare const Left: <L extends Type, R extends Type>(value: L) => Either<L, R>;
|
|
4442
|
+
declare const isRight: <L extends Type, R extends Type>(either: Either<L, R>) => either is Either<L, R> & {
|
|
4443
|
+
value: R;
|
|
4444
|
+
};
|
|
4445
|
+
declare const isLeft: <L extends Type, R extends Type>(either: Either<L, R>) => either is Either<L, R> & {
|
|
4446
|
+
value: L;
|
|
4447
|
+
};
|
|
4448
|
+
declare const tryCatch: <L extends Type, R extends Type>(f: () => R, onError: (error: unknown) => L) => Either<L, R>;
|
|
4449
|
+
declare const TypeCheckRight: <L extends Type, R extends Type>(value: R) => TestEither<L, R>;
|
|
4450
|
+
declare const TypeCheckLeft: <L extends Type, R extends Type>(value: L) => TestEither<L, R>;
|
|
4451
|
+
declare const tryCatchAsync: <L extends Type, R extends Type>(f: () => Promise<R>, onError: (error: unknown) => L) => Promise<Either<L, R>>;
|
|
4452
|
+
declare const Either: (<L extends Type, R extends Type>(value: R | L, isRight: boolean) => Either<L, R>) & {
|
|
4453
|
+
/**
|
|
4454
|
+
* Creates a Left instance
|
|
4455
|
+
* @param value - The left value
|
|
4456
|
+
* @returns Left Either
|
|
4457
|
+
*/
|
|
4458
|
+
left: <L extends Type, R extends Type>(value: L) => Either<L, R>;
|
|
4459
|
+
/**
|
|
4460
|
+
* Creates a Right instance
|
|
4461
|
+
* @param value - The right value
|
|
4462
|
+
* @returns Right Either
|
|
4463
|
+
*/
|
|
4464
|
+
right: <L extends Type, R extends Type>(value: R) => Either<L, R>;
|
|
4465
|
+
/**
|
|
4466
|
+
* Type guard to check if an Either is Right
|
|
4467
|
+
* @param either - The Either to check
|
|
4468
|
+
* @returns True if Either is Right
|
|
4469
|
+
*/
|
|
4470
|
+
isRight: <L extends Type, R extends Type>(either: Either<L, R>) => either is Either<L, R> & {
|
|
4471
|
+
value: R;
|
|
4472
|
+
};
|
|
4473
|
+
/**
|
|
4474
|
+
* Type guard to check if an Either is Left
|
|
4475
|
+
* @param either - The Either to check
|
|
4476
|
+
* @returns True if Either is Left
|
|
4477
|
+
*/
|
|
4478
|
+
isLeft: <L extends Type, R extends Type>(either: Either<L, R>) => either is Either<L, R> & {
|
|
4479
|
+
value: L;
|
|
4480
|
+
};
|
|
4481
|
+
/**
|
|
4482
|
+
* Combines an array of Eithers into a single Either containing an array
|
|
4483
|
+
* @param eithers - Array of Either values
|
|
4484
|
+
* @returns Either with array of values or first Left encountered
|
|
4485
|
+
*/
|
|
4486
|
+
sequence: <L extends Type, R extends Type>(eithers: Either<L, R>[]) => Either<L, R[]>;
|
|
4487
|
+
/**
|
|
4488
|
+
* Maps an array through a function that returns Either, then sequences the results
|
|
4489
|
+
* @param arr - Array of values
|
|
4490
|
+
* @param f - Function that returns Either
|
|
4491
|
+
* @returns Either with array of results or first Left encountered
|
|
4492
|
+
*/
|
|
4493
|
+
traverse: <L extends Type, R extends Type, U extends Type>(arr: R[], f: (value: R) => Either<L, U>) => Either<L, U[]>;
|
|
4494
|
+
/**
|
|
4495
|
+
* Creates an Either from a nullable value
|
|
4496
|
+
* @param value - The value that might be null or undefined
|
|
4497
|
+
* @param leftValue - The value to use for Left if value is null/undefined
|
|
4498
|
+
* @returns Right if value is not null/undefined, Left otherwise
|
|
4499
|
+
*/
|
|
4500
|
+
fromNullable: <L extends Type, R extends Type>(value: R | null | undefined, leftValue: L) => Either<L, R>;
|
|
4501
|
+
/**
|
|
4502
|
+
* Creates an Either based on a predicate
|
|
4503
|
+
* @param value - The value to test
|
|
4504
|
+
* @param predicate - The predicate function
|
|
4505
|
+
* @param leftValue - The value to use for Left if predicate fails
|
|
4506
|
+
* @returns Right if predicate passes, Left otherwise
|
|
4507
|
+
*/
|
|
4508
|
+
fromPredicate: <L extends Type, R extends Type>(value: R, predicate: (value: R) => boolean, leftValue: L) => Either<L, R>;
|
|
4509
|
+
/**
|
|
4510
|
+
* Applicative apply - applies a wrapped function to a wrapped value
|
|
4511
|
+
* @param eitherF - Either containing a function
|
|
4512
|
+
* @param eitherV - Either containing a value
|
|
4513
|
+
* @returns Either with function applied to value
|
|
4514
|
+
*/
|
|
4515
|
+
ap: <L extends Type, R extends Type, U extends Type>(eitherF: Either<L, (value: R) => U>, eitherV: Either<L, R>) => Either<L, U>;
|
|
4516
|
+
/**
|
|
4517
|
+
* Creates an Either from a Promise
|
|
4518
|
+
* @param promise - The Promise to convert
|
|
4519
|
+
* @param onRejected - Function to convert rejection reason to Left value
|
|
4520
|
+
* @returns Promise that resolves to Either
|
|
4521
|
+
*/
|
|
4522
|
+
fromPromise: <L, R>(promise: Promise<R>, onRejected: (reason: unknown) => L) => Promise<Either<L, R>>;
|
|
4523
|
+
/**
|
|
4524
|
+
* Creates an Either from JSON string
|
|
4525
|
+
* @param json - The JSON string
|
|
4526
|
+
* @returns Either instance
|
|
4527
|
+
*/
|
|
4528
|
+
fromJSON: <L extends Type, R extends Type>(json: string) => Either<L, R>;
|
|
4529
|
+
/**
|
|
4530
|
+
* Creates an Either from YAML string
|
|
4531
|
+
* @param yaml - The YAML string
|
|
4532
|
+
* @returns Either instance
|
|
4533
|
+
*/
|
|
4534
|
+
fromYAML: <L extends Type, R extends Type>(yaml: string) => Either<L, R>;
|
|
4535
|
+
/**
|
|
4536
|
+
* Creates an Either from binary string
|
|
4537
|
+
* @param binary - The binary string
|
|
4538
|
+
* @returns Either instance
|
|
4539
|
+
*/
|
|
4540
|
+
fromBinary: <L extends Type, R extends Type>(binary: string) => Either<L, R>;
|
|
4541
|
+
};
|
|
4542
|
+
//#endregion
|
|
4543
|
+
//#region src/do/index.d.ts
|
|
4544
|
+
type OptionLike = {
|
|
4545
|
+
_tag: "Some" | "None";
|
|
4546
|
+
isSome(): boolean;
|
|
4547
|
+
get(): unknown;
|
|
4548
|
+
};
|
|
4549
|
+
type EitherLike = {
|
|
4550
|
+
_tag: "Left" | "Right";
|
|
4551
|
+
isLeft(): boolean;
|
|
4552
|
+
isRight(): boolean;
|
|
4553
|
+
value: unknown;
|
|
4554
|
+
};
|
|
4555
|
+
type ListLike = {
|
|
4556
|
+
_tag: "List";
|
|
4557
|
+
toArray(): unknown[];
|
|
4558
|
+
};
|
|
4559
|
+
type TryLike = {
|
|
4560
|
+
_tag: "Success" | "Failure";
|
|
4561
|
+
isSuccess(): boolean;
|
|
4562
|
+
get(): unknown;
|
|
4563
|
+
};
|
|
4564
|
+
/**
|
|
4565
|
+
* Executes a generator-based monadic comprehension
|
|
4566
|
+
* Returns the same monad type as the first yielded monad (Scala semantics)
|
|
4567
|
+
*
|
|
4568
|
+
* - Option comprehensions return Option (None on short-circuit)
|
|
4569
|
+
* - Either comprehensions return Either (Left with error on short-circuit)
|
|
4570
|
+
* - List comprehensions return List (empty or cartesian product)
|
|
4571
|
+
* - Try comprehensions return Try (Failure with error on short-circuit)
|
|
4572
|
+
*
|
|
4573
|
+
* Type Inference Notes:
|
|
4574
|
+
* - TypeScript infers the correct return type for homogeneous comprehensions
|
|
4575
|
+
* - For mixed monad types, TypeScript returns a union type
|
|
4576
|
+
* - Use DoTyped<T> or type assertions for mixed scenarios
|
|
4577
|
+
*
|
|
4578
|
+
* @example
|
|
4579
|
+
* ```typescript
|
|
4580
|
+
* // Option comprehension returns Option:
|
|
4581
|
+
* const result = Do(function* () {
|
|
4582
|
+
* const x = yield* $(Option(5));
|
|
4583
|
+
* const y = yield* $(Option(10));
|
|
4584
|
+
* return x + y;
|
|
4585
|
+
* });
|
|
4586
|
+
* // result: Option(15)
|
|
4587
|
+
*
|
|
4588
|
+
* // Either comprehension returns Either:
|
|
4589
|
+
* const result = Do(function* () {
|
|
4590
|
+
* const x = yield* $(Right(5));
|
|
4591
|
+
* const y = yield* $(Left("error"));
|
|
4592
|
+
* return x + y;
|
|
4593
|
+
* });
|
|
4594
|
+
* // result: Left("error") - error is preserved
|
|
4595
|
+
*
|
|
4596
|
+
* // List comprehension returns List with cartesian product:
|
|
4597
|
+
* const result = Do(function* () {
|
|
4598
|
+
* const x = yield* $(List([1, 2]));
|
|
4599
|
+
* const y = yield* $(List([3, 4]));
|
|
4600
|
+
* return x + y;
|
|
4601
|
+
* });
|
|
4602
|
+
* // result: List([4, 5, 5, 6])
|
|
4603
|
+
*
|
|
4604
|
+
* // Mixed types - use type assertion or DoTyped:
|
|
4605
|
+
* const result = Do(function* () {
|
|
4606
|
+
* const x = yield* $(Option(5));
|
|
4607
|
+
* const y = yield* $(Right<string, number>(10));
|
|
4608
|
+
* return x + y;
|
|
4609
|
+
* }) as Option<number>;
|
|
4610
|
+
* // result: Option(15)
|
|
4611
|
+
* ```
|
|
4612
|
+
*
|
|
4613
|
+
* @param gen - Generator function that yields monads and returns a result
|
|
4614
|
+
* @returns The same monad type as the first yield
|
|
4615
|
+
*/
|
|
4616
|
+
declare function Do<T>(gen: () => Generator<OptionLike, T, unknown>): Option<T>;
|
|
4617
|
+
declare function Do<L, R>(gen: () => Generator<EitherLike, R, unknown>): Either<L, R>;
|
|
4618
|
+
declare function Do<T>(gen: () => Generator<ListLike, T, unknown>): List<T>;
|
|
4619
|
+
declare function Do<T>(gen: () => Generator<TryLike, T, unknown>): Try<T>;
|
|
4620
|
+
declare function Do<T>(gen: () => Generator<OptionLike | EitherLike | ListLike | TryLike, T, unknown>): Reshapeable<T>;
|
|
4621
|
+
declare function Do<T>(gen: () => Generator<unknown, T, unknown>): unknown;
|
|
4622
|
+
/**
|
|
4623
|
+
* Executes an async generator-based monadic comprehension
|
|
4624
|
+
* Returns the same monad type as the first yielded monad
|
|
4625
|
+
*
|
|
4626
|
+
* @example
|
|
4627
|
+
* ```typescript
|
|
4628
|
+
* const result = await DoAsync(async function* () {
|
|
4629
|
+
* const user = yield* $(await fetchUser(id)); // Promise<Option<User>> → User
|
|
4630
|
+
* const profile = yield* $(await getProfile(user)); // Promise<Either<Error, Profile>> → Profile
|
|
4631
|
+
* return { user, profile };
|
|
4632
|
+
* });
|
|
4633
|
+
* // result type matches first yield
|
|
4634
|
+
* ```
|
|
4635
|
+
*
|
|
4636
|
+
* @param gen - Async generator function that yields monads/promises and returns a result
|
|
4637
|
+
* @returns Promise of the same monad type as first yield
|
|
4638
|
+
*/
|
|
4639
|
+
declare function DoAsync<T>(gen: () => AsyncGenerator<OptionLike, T, unknown>): Promise<Option<T>>;
|
|
4640
|
+
declare function DoAsync<L, R>(gen: () => AsyncGenerator<EitherLike, R, unknown>): Promise<Either<L, R>>;
|
|
4641
|
+
declare function DoAsync<T>(gen: () => AsyncGenerator<ListLike, T, unknown>): Promise<List<T>>;
|
|
4642
|
+
declare function DoAsync<T>(gen: () => AsyncGenerator<TryLike, T, unknown>): Promise<Try<T>>;
|
|
4643
|
+
declare function DoAsync<T>(gen: () => AsyncGenerator<OptionLike | EitherLike | ListLike | TryLike, T, unknown>): Promise<Reshapeable<T>>;
|
|
4644
|
+
declare function DoAsync<T>(gen: () => AsyncGenerator<unknown, T, unknown>): Promise<unknown>;
|
|
4645
|
+
/**
|
|
4646
|
+
* Helper function to check if a value implements the Doable interface
|
|
4647
|
+
* @param value - Value to check
|
|
4648
|
+
* @returns True if the value implements Doable
|
|
4649
|
+
*/
|
|
4650
|
+
declare function isDoCapable<T>(value: unknown): value is Doable<T>;
|
|
4651
|
+
/**
|
|
4652
|
+
* Manually unwrap a monad using the Doable interface
|
|
4653
|
+
* Useful for testing or when you need to unwrap outside of a Do-comprehension
|
|
4654
|
+
*
|
|
4655
|
+
* @param monad - Monad to unwrap
|
|
4656
|
+
* @returns The unwrapped value
|
|
4657
|
+
* @throws Error if the monad cannot be unwrapped
|
|
4658
|
+
*/
|
|
4659
|
+
declare function unwrap<T>(monad: Doable<T>): T;
|
|
4660
|
+
/**
|
|
4661
|
+
* Type helper for Do-notation generators.
|
|
4662
|
+
* Provides better type hints in IDEs.
|
|
4663
|
+
*
|
|
4664
|
+
* @example
|
|
4665
|
+
* ```typescript
|
|
4666
|
+
* const result = Do(function* (): DoGenerator<number> {
|
|
4667
|
+
* const x = yield* $(List([1, 2])) // x is still unknown but return type is clear
|
|
4668
|
+
* const y = yield* $(List([3, 4]))
|
|
4669
|
+
* return x + y
|
|
4670
|
+
* })
|
|
4671
|
+
* ```
|
|
4672
|
+
*/
|
|
4673
|
+
type DoGenerator<T, TYield = unknown> = Generator<TYield, T, unknown>;
|
|
4674
|
+
/**
|
|
4675
|
+
* Extracts values from monads in Do-notation with type inference.
|
|
4676
|
+
* The '$' symbol is the universal extraction operator in functional programming.
|
|
4677
|
+
*
|
|
4678
|
+
* @example
|
|
4679
|
+
* ```typescript
|
|
4680
|
+
* const result = Do(function* () {
|
|
4681
|
+
* const x = yield* $(Option(5)) // x: number
|
|
4682
|
+
* const y = yield* $(List([1, 2, 3])) // y: number (for cartesian product)
|
|
4683
|
+
* const name = yield* $(Right("Alice")) // name: string
|
|
4684
|
+
* return `${name}: ${x + y}`
|
|
4685
|
+
* })
|
|
4686
|
+
* ```
|
|
4687
|
+
*
|
|
4688
|
+
* @param monad - Any monad that can be unwrapped (Option, Either, List, Try, etc.)
|
|
4689
|
+
* @returns A generator that yields the monad and returns its extracted value
|
|
4690
|
+
*/
|
|
4691
|
+
declare function $<T>(monad: Option<T>): Generator<Option<T>, T, T>;
|
|
4692
|
+
declare function $<L, R>(monad: Either<L, R>): Generator<Either<L, R>, R, R>;
|
|
4693
|
+
declare function $<T>(monad: List<T>): Generator<List<T>, T, T>;
|
|
4694
|
+
declare function $<T>(monad: Try<T>): Generator<Try<T>, T, T>;
|
|
4695
|
+
declare function $<T>(monad: Doable<T>): Generator<Doable<T>, T, T>;
|
|
4696
|
+
declare function $<M>(monad: M): Generator<M, InferYieldType<M>, InferYieldType<M>>;
|
|
4697
|
+
type InferYieldType<M> = M extends {
|
|
4698
|
+
isSome(): boolean;
|
|
4699
|
+
get(): infer T;
|
|
4700
|
+
} ? T : M extends {
|
|
4701
|
+
isRight(): boolean;
|
|
4702
|
+
value: infer R;
|
|
4703
|
+
} ? R : M extends {
|
|
4704
|
+
toArray(): (infer T)[];
|
|
4705
|
+
} ? T : M extends {
|
|
4706
|
+
isSuccess(): boolean;
|
|
4707
|
+
get(): infer T;
|
|
4708
|
+
} ? T : M extends Doable<infer T> ? T : unknown;
|
|
4709
|
+
declare const NoneError: (message?: string) => Error;
|
|
4710
|
+
interface LeftErrorType<L> extends Error {
|
|
4711
|
+
value: L;
|
|
4712
|
+
}
|
|
4713
|
+
declare const LeftError: <L>(value: L, message?: string) => LeftErrorType<L>;
|
|
4714
|
+
declare const EmptyListError: (message?: string) => Error;
|
|
4715
|
+
interface FailureErrorType extends Error {
|
|
4716
|
+
cause: Error;
|
|
4717
|
+
}
|
|
4718
|
+
declare const FailureError: (cause: Error, message?: string) => FailureErrorType;
|
|
4719
|
+
//#endregion
|
|
4720
|
+
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 };
|