functype 0.44.0 → 0.46.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/README.md +1 -2
- package/dist/Companion-VlxcFhzb.js +1 -0
- package/dist/{index-DKAUrDCz.d.ts → Functype-Dc440LS5.d.ts} +211 -1378
- package/dist/{Tuple-C4maYbiO.d.ts → Typeable-E4-aX9Gc.d.ts} +1 -74
- package/dist/Valuable-B8h0iKI_.js +13 -0
- package/dist/branded/index.d.ts +53 -1
- package/dist/branded/index.js +1 -1
- package/dist/cli/index.js +33 -28
- package/dist/do/index.d.ts +184 -2
- package/dist/do/index.js +1 -1
- package/dist/either/index.d.ts +187 -1
- package/dist/either/index.js +2 -1
- package/dist/index.d.ts +12 -4
- package/dist/index.js +1 -1
- package/dist/list/index.d.ts +84 -1
- package/dist/list/index.js +2 -1
- package/dist/map/index.d.ts +71 -1
- package/dist/map/index.js +2 -1
- package/dist/option/index.d.ts +242 -1
- package/dist/option/index.js +2 -1
- package/dist/set/index.d.ts +53 -1
- package/dist/set/index.js +2 -1
- package/dist/try/index.d.ts +96 -1
- package/dist/try/index.js +2 -1
- package/dist/tuple/index.d.ts +75 -1
- package/dist/tuple/index.js +1 -1
- package/package.json +7 -12
- package/dist/Brand-BPeggBaO.d.ts +0 -54
- package/dist/Brand-Cfr5zy8F.js +0 -1
- package/dist/Tuple-CUljR3nx.js +0 -1
- package/dist/fpromise/index.d.ts +0 -2
- package/dist/fpromise/index.js +0 -1
- package/dist/src-BuPnddUO.js +0 -19
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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-E4-aX9Gc.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";
|
|
3
8
|
|
|
4
9
|
//#region src/error/ParseError.d.ts
|
|
5
10
|
declare const ParseError: (message?: string) => Error & {
|
|
@@ -125,6 +130,16 @@ interface LazyList<A extends Type> extends Foldable<A>, Pipe<LazyList<A>>, Seria
|
|
|
125
130
|
dropWhile(predicate: (a: A) => boolean): LazyList<A>;
|
|
126
131
|
concat(other: LazyList<A>): LazyList<A>;
|
|
127
132
|
zip<B extends Type>(other: LazyList<B>): LazyList<[A, B]>;
|
|
133
|
+
takeRight(n: number): LazyList<A>;
|
|
134
|
+
reverse(): LazyList<A>;
|
|
135
|
+
distinct(): LazyList<A>;
|
|
136
|
+
zipWithIndex(): LazyList<[A, number]>;
|
|
137
|
+
get head(): A | undefined;
|
|
138
|
+
get headOption(): Option<A>;
|
|
139
|
+
get last(): A | undefined;
|
|
140
|
+
get lastOption(): Option<A>;
|
|
141
|
+
get tail(): LazyList<A>;
|
|
142
|
+
get init(): LazyList<A>;
|
|
128
143
|
toList(): List<A>;
|
|
129
144
|
toArray(): A[];
|
|
130
145
|
forEach(f: (a: A) => void): void;
|
|
@@ -133,8 +148,6 @@ interface LazyList<A extends Type> extends Foldable<A>, Pipe<LazyList<A>>, Seria
|
|
|
133
148
|
some(predicate: (a: A) => boolean): boolean;
|
|
134
149
|
every(predicate: (a: A) => boolean): boolean;
|
|
135
150
|
count(): number;
|
|
136
|
-
first(): Option<A>;
|
|
137
|
-
last(): Option<A>;
|
|
138
151
|
toString(): string;
|
|
139
152
|
}
|
|
140
153
|
/**
|
|
@@ -292,6 +305,34 @@ interface CollectionOps<A extends Type, Self> {
|
|
|
292
305
|
* Gets the first element wrapped in Option.
|
|
293
306
|
*/
|
|
294
307
|
get headOption(): Option<A>;
|
|
308
|
+
/**
|
|
309
|
+
* Takes the first n elements from the collection.
|
|
310
|
+
*/
|
|
311
|
+
take(n: number): Self;
|
|
312
|
+
/**
|
|
313
|
+
* Takes elements from the start while the predicate is true.
|
|
314
|
+
*/
|
|
315
|
+
takeWhile(p: (a: A) => boolean): Self;
|
|
316
|
+
/**
|
|
317
|
+
* Takes the last n elements from the collection.
|
|
318
|
+
*/
|
|
319
|
+
takeRight(n: number): Self;
|
|
320
|
+
/**
|
|
321
|
+
* Gets the last element of the collection.
|
|
322
|
+
*/
|
|
323
|
+
get last(): A | undefined;
|
|
324
|
+
/**
|
|
325
|
+
* Gets the last element wrapped in Option.
|
|
326
|
+
*/
|
|
327
|
+
get lastOption(): Option<A>;
|
|
328
|
+
/**
|
|
329
|
+
* Gets all elements except the first.
|
|
330
|
+
*/
|
|
331
|
+
get tail(): Self;
|
|
332
|
+
/**
|
|
333
|
+
* Gets all elements except the last.
|
|
334
|
+
*/
|
|
335
|
+
get init(): Self;
|
|
295
336
|
/**
|
|
296
337
|
* Converts the collection to an array.
|
|
297
338
|
*/
|
|
@@ -374,96 +415,6 @@ interface Promisable<A extends Type> {
|
|
|
374
415
|
toPromise(): Promise<A>;
|
|
375
416
|
}
|
|
376
417
|
//#endregion
|
|
377
|
-
//#region src/try/Try.d.ts
|
|
378
|
-
/**
|
|
379
|
-
* Possible types of Try instances
|
|
380
|
-
*/
|
|
381
|
-
type TypeNames = "Success" | "Failure";
|
|
382
|
-
interface Try<T> extends FunctypeBase<T, TypeNames>, Extractable<T>, Pipe<T>, Promisable<T>, Doable<T>, Reshapeable<T> {
|
|
383
|
-
readonly _tag: TypeNames;
|
|
384
|
-
readonly error: Error | undefined;
|
|
385
|
-
isSuccess(): this is Try<T> & {
|
|
386
|
-
readonly _tag: "Success";
|
|
387
|
-
error: undefined;
|
|
388
|
-
};
|
|
389
|
-
isFailure(): this is Try<T> & {
|
|
390
|
-
readonly _tag: "Failure";
|
|
391
|
-
error: Error;
|
|
392
|
-
};
|
|
393
|
-
orElse: (defaultValue: T) => T;
|
|
394
|
-
orThrow: (error?: Error) => T;
|
|
395
|
-
or: (alternative: Try<T>) => Try<T>;
|
|
396
|
-
orNull: () => T | null;
|
|
397
|
-
orUndefined: () => T | undefined;
|
|
398
|
-
toOption: () => Option<T>;
|
|
399
|
-
toEither: <E extends Type>(leftValue: E) => Either<E, T>;
|
|
400
|
-
toList: () => List<T>;
|
|
401
|
-
toTry: () => Try<T>;
|
|
402
|
-
map: <U>(f: (value: T) => U) => Try<U>;
|
|
403
|
-
ap: <U>(ff: Try<(value: T) => U>) => Try<U>;
|
|
404
|
-
flatMap: <U>(f: (value: T) => Try<U>) => Try<U>;
|
|
405
|
-
flatMapAsync: <U>(f: (value: T) => Promise<Try<U>>) => Promise<Try<U>>;
|
|
406
|
-
/**
|
|
407
|
-
* Pattern matches over the Try, applying onFailure if Failure and onSuccess if Success
|
|
408
|
-
* @param onFailure - Function to apply if the Try is Failure
|
|
409
|
-
* @param onSuccess - Function to apply if the Try is Success
|
|
410
|
-
* @returns The result of applying the appropriate function
|
|
411
|
-
*/
|
|
412
|
-
fold: <U extends Type>(onFailure: (error: Error) => U, onSuccess: (value: T) => U) => U;
|
|
413
|
-
toString: () => string;
|
|
414
|
-
/**
|
|
415
|
-
* Pattern matches over the Try, applying a handler function based on the variant
|
|
416
|
-
* @param patterns - Object with handler functions for Success and Failure variants
|
|
417
|
-
* @returns The result of applying the matching handler function
|
|
418
|
-
*/
|
|
419
|
-
match<R$1>(patterns: {
|
|
420
|
-
Success: (value: T) => R$1;
|
|
421
|
-
Failure: (error: Error) => R$1;
|
|
422
|
-
}): R$1;
|
|
423
|
-
toValue(): {
|
|
424
|
-
_tag: TypeNames;
|
|
425
|
-
value: T | Error;
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
declare const Try: (<T>(f: () => T) => Try<T>) & {
|
|
429
|
-
/**
|
|
430
|
-
* Type guard to check if a Try is Success
|
|
431
|
-
* @param tryValue - The Try to check
|
|
432
|
-
* @returns True if Try is Success
|
|
433
|
-
*/
|
|
434
|
-
isSuccess: <T>(tryValue: Try<T>) => tryValue is Try<T> & {
|
|
435
|
-
readonly _tag: "Success";
|
|
436
|
-
error: undefined;
|
|
437
|
-
};
|
|
438
|
-
/**
|
|
439
|
-
* Type guard to check if a Try is Failure
|
|
440
|
-
* @param tryValue - The Try to check
|
|
441
|
-
* @returns True if Try is Failure
|
|
442
|
-
*/
|
|
443
|
-
isFailure: <T>(tryValue: Try<T>) => tryValue is Try<T> & {
|
|
444
|
-
readonly _tag: "Failure";
|
|
445
|
-
error: Error;
|
|
446
|
-
};
|
|
447
|
-
/**
|
|
448
|
-
* Creates a Try from JSON string
|
|
449
|
-
* @param json - The JSON string
|
|
450
|
-
* @returns Try instance
|
|
451
|
-
*/
|
|
452
|
-
fromJSON: <T>(json: string) => Try<T>;
|
|
453
|
-
/**
|
|
454
|
-
* Creates a Try from YAML string
|
|
455
|
-
* @param yaml - The YAML string
|
|
456
|
-
* @returns Try instance
|
|
457
|
-
*/
|
|
458
|
-
fromYAML: <T>(yaml: string) => Try<T>;
|
|
459
|
-
/**
|
|
460
|
-
* Creates a Try from binary string
|
|
461
|
-
* @param binary - The binary string
|
|
462
|
-
* @returns Try instance
|
|
463
|
-
*/
|
|
464
|
-
fromBinary: <T>(binary: string) => Try<T>;
|
|
465
|
-
};
|
|
466
|
-
//#endregion
|
|
467
418
|
//#region src/reshapeable/Reshapeable.d.ts
|
|
468
419
|
/**
|
|
469
420
|
* Interface for types that can be reshaped (converted) between different monadic containers.
|
|
@@ -551,18 +502,18 @@ interface Reshapeable<T extends Type> {
|
|
|
551
502
|
}
|
|
552
503
|
//#endregion
|
|
553
504
|
//#region src/branded/ValidatedBrand.d.ts
|
|
554
|
-
type ValidatedBrand<K
|
|
505
|
+
type ValidatedBrand<K extends string, T> = Brand<K, T> & {
|
|
555
506
|
readonly __validated: true;
|
|
556
507
|
};
|
|
557
|
-
interface ValidatedBrandCompanion<K
|
|
558
|
-
readonly brand: K
|
|
508
|
+
interface ValidatedBrandCompanion<K extends string, T> {
|
|
509
|
+
readonly brand: K;
|
|
559
510
|
readonly validate: (value: T) => boolean;
|
|
560
|
-
readonly of: (value: T) => Option<ValidatedBrand<K
|
|
561
|
-
readonly from: (value: T) => Either<string, ValidatedBrand<K
|
|
562
|
-
readonly unsafeOf: (value: T) => ValidatedBrand<K
|
|
563
|
-
readonly is: (value: unknown) => value is ValidatedBrand<K
|
|
564
|
-
readonly unwrap: (branded: Brand<K
|
|
565
|
-
readonly refine: <K2 extends string>(brand: K2, validate: (value: Brand<K
|
|
511
|
+
readonly of: (value: T) => Option<ValidatedBrand<K, T>>;
|
|
512
|
+
readonly from: (value: T) => Either<string, ValidatedBrand<K, T>>;
|
|
513
|
+
readonly unsafeOf: (value: T) => ValidatedBrand<K, T>;
|
|
514
|
+
readonly is: (value: unknown) => value is ValidatedBrand<K, T>;
|
|
515
|
+
readonly unwrap: (branded: Brand<K, T>) => T;
|
|
516
|
+
readonly refine: <K2 extends string>(brand: K2, validate: (value: Brand<K, T>) => boolean) => ValidatedBrandCompanion<K2, Brand<K, T>>;
|
|
566
517
|
}
|
|
567
518
|
/**
|
|
568
519
|
* Create a validated brand with runtime validation
|
|
@@ -597,7 +548,7 @@ interface ValidatedBrandCompanion<K$1 extends string, T> {
|
|
|
597
548
|
* // ❌ ValidatedBrand("ValidatedUserId", ...) + Brand<"UserId", string>
|
|
598
549
|
* // ✅ ValidatedBrand("UserId", ...) + Brand<"UserId", string>
|
|
599
550
|
*/
|
|
600
|
-
declare function ValidatedBrand<K
|
|
551
|
+
declare function ValidatedBrand<K extends string, T>(brand: K, validate: (value: T) => boolean): ValidatedBrandCompanion<K, T>;
|
|
601
552
|
/**
|
|
602
553
|
* Positive number brand (> 0)
|
|
603
554
|
* @example
|
|
@@ -835,7 +786,7 @@ declare const Cond: (<T extends Type>() => Cond<T>) & {
|
|
|
835
786
|
* "skip": () => defaultValue
|
|
836
787
|
* })
|
|
837
788
|
*/
|
|
838
|
-
match: <T extends string | number | symbol>(value: T) => <R
|
|
789
|
+
match: <T extends string | number | symbol>(value: T) => <R extends Type>(cases: Record<T, R | (() => R)>) => R;
|
|
839
790
|
/**
|
|
840
791
|
* Create a lazy conditional that defers evaluation
|
|
841
792
|
* @example
|
|
@@ -882,7 +833,7 @@ type Pattern<T> = T | { [K in keyof T]?: Pattern<T[K]> } | ((value: T) => boolea
|
|
|
882
833
|
* Extract result from pattern
|
|
883
834
|
* @internal
|
|
884
835
|
*/
|
|
885
|
-
type PatternResult<T, R
|
|
836
|
+
type PatternResult<T, R> = R | ((matched: T) => R);
|
|
886
837
|
/**
|
|
887
838
|
* Untyped Match (before first case is added).
|
|
888
839
|
* The result type R is inferred when the first case method is called.
|
|
@@ -894,23 +845,23 @@ type UntypedMatch<T extends Type> = {
|
|
|
894
845
|
/**
|
|
895
846
|
* Match against a pattern - infers result type R from the result parameter
|
|
896
847
|
*/
|
|
897
|
-
case: <R
|
|
848
|
+
case: <R extends Type>(pattern: Pattern<T>, result: PatternResult<T, R>) => Match<T, R>;
|
|
898
849
|
/**
|
|
899
850
|
* Match a specific value - infers result type R from the result parameter
|
|
900
851
|
*/
|
|
901
|
-
caseValue: <R
|
|
852
|
+
caseValue: <R extends Type>(match: T, result: R | (() => R)) => Match<T, R>;
|
|
902
853
|
/**
|
|
903
854
|
* Match multiple values - infers result type R from the result parameter
|
|
904
855
|
*/
|
|
905
|
-
caseValues: <R
|
|
856
|
+
caseValues: <R extends Type>(matches: T[], result: R | (() => R)) => Match<T, R>;
|
|
906
857
|
/**
|
|
907
858
|
* Match with a guard function - infers result type R from the result parameter
|
|
908
859
|
*/
|
|
909
|
-
when: <R
|
|
860
|
+
when: <R extends Type>(guard: (value: T) => boolean, result: PatternResult<T, R>) => Match<T, R>;
|
|
910
861
|
/**
|
|
911
862
|
* Match multiple patterns (OR operation) - infers result type R from the result parameter
|
|
912
863
|
*/
|
|
913
|
-
caseAny: <R
|
|
864
|
+
caseAny: <R extends Type>(patterns: Pattern<T>[], result: PatternResult<T, R>) => Match<T, R>;
|
|
914
865
|
};
|
|
915
866
|
/**
|
|
916
867
|
* Pattern matching construct similar to Scala's match expressions.
|
|
@@ -939,49 +890,49 @@ type UntypedMatch<T extends Type> = {
|
|
|
939
890
|
* .case({ role: "user" }, u => `User: ${u.name}`)
|
|
940
891
|
* .default("Guest")
|
|
941
892
|
*/
|
|
942
|
-
type Match<T extends Type, R
|
|
893
|
+
type Match<T extends Type, R extends Type> = {
|
|
943
894
|
/**
|
|
944
895
|
* Match against a pattern (value, nested object, or predicate).
|
|
945
896
|
* The result type R2 is added to the union of possible results.
|
|
946
897
|
*/
|
|
947
|
-
case: <R2 extends Type>(pattern: Pattern<T>, result: PatternResult<T, R2>) => Match<T, R
|
|
898
|
+
case: <R2 extends Type>(pattern: Pattern<T>, result: PatternResult<T, R2>) => Match<T, R | R2>;
|
|
948
899
|
/**
|
|
949
900
|
* Add a case that matches a specific value.
|
|
950
901
|
* The result type R2 is added to the union of possible results.
|
|
951
902
|
*/
|
|
952
|
-
caseValue: <R2 extends Type>(match: T, result: R2 | (() => R2)) => Match<T, R
|
|
903
|
+
caseValue: <R2 extends Type>(match: T, result: R2 | (() => R2)) => Match<T, R | R2>;
|
|
953
904
|
/**
|
|
954
905
|
* Add a case that matches multiple values.
|
|
955
906
|
* The result type R2 is added to the union of possible results.
|
|
956
907
|
*/
|
|
957
|
-
caseValues: <R2 extends Type>(matches: T[], result: R2 | (() => R2)) => Match<T, R
|
|
908
|
+
caseValues: <R2 extends Type>(matches: T[], result: R2 | (() => R2)) => Match<T, R | R2>;
|
|
958
909
|
/**
|
|
959
910
|
* Match with a guard function (alias for readability).
|
|
960
911
|
* The result type R2 is added to the union of possible results.
|
|
961
912
|
*/
|
|
962
|
-
when: <R2 extends Type>(guard: (value: T) => boolean, result: PatternResult<T, R2>) => Match<T, R
|
|
913
|
+
when: <R2 extends Type>(guard: (value: T) => boolean, result: PatternResult<T, R2>) => Match<T, R | R2>;
|
|
963
914
|
/**
|
|
964
915
|
* Match multiple patterns (OR operation).
|
|
965
916
|
* The result type R2 is added to the union of possible results.
|
|
966
917
|
*/
|
|
967
|
-
caseAny: <R2 extends Type>(patterns: Pattern<T>[], result: PatternResult<T, R2>) => Match<T, R
|
|
918
|
+
caseAny: <R2 extends Type>(patterns: Pattern<T>[], result: PatternResult<T, R2>) => Match<T, R | R2>;
|
|
968
919
|
/**
|
|
969
920
|
* Default case - makes match non-exhaustive.
|
|
970
921
|
* The result type R2 is added to the union of possible results.
|
|
971
922
|
*/
|
|
972
|
-
default: <R2 extends Type>(result: PatternResult<T, R2>) => R
|
|
923
|
+
default: <R2 extends Type>(result: PatternResult<T, R2>) => R | R2;
|
|
973
924
|
/**
|
|
974
925
|
* Force exhaustive matching (compile-time check for union types)
|
|
975
926
|
*/
|
|
976
|
-
exhaustive: () => R
|
|
927
|
+
exhaustive: () => R;
|
|
977
928
|
/**
|
|
978
929
|
* Get result if matched, throws if no match
|
|
979
930
|
*/
|
|
980
|
-
orThrow: (errorMessage?: string) => R
|
|
931
|
+
orThrow: (errorMessage?: string) => R;
|
|
981
932
|
/**
|
|
982
933
|
* Get result wrapped in Option
|
|
983
934
|
*/
|
|
984
|
-
toOption: () => Option<R
|
|
935
|
+
toOption: () => Option<R>;
|
|
985
936
|
};
|
|
986
937
|
/**
|
|
987
938
|
* Pattern matching utility for type-safe conditional logic with exhaustiveness checking,
|
|
@@ -1047,7 +998,7 @@ declare const Match: (<T extends Type>(value: T) => UntypedMatch<T>) & {
|
|
|
1047
998
|
* const compute = ops("multiply").fn
|
|
1048
999
|
* const result = compute(4, 5) // 20
|
|
1049
1000
|
*/
|
|
1050
|
-
exhaustive: <T extends string | number | symbol, R
|
|
1001
|
+
exhaustive: <T extends string | number | symbol, R extends Type>(cases: RequireExhaustive<T, Record<T, R>>) => (value: T) => R;
|
|
1051
1002
|
/**
|
|
1052
1003
|
* Create a partial match that requires a default
|
|
1053
1004
|
* @example
|
|
@@ -1069,8 +1020,8 @@ declare const Match: (<T extends Type>(value: T) => UntypedMatch<T>) & {
|
|
|
1069
1020
|
* }).withDefault((n) => `Number: ${n}`)
|
|
1070
1021
|
* getMessage(5) // "Number: 5"
|
|
1071
1022
|
*/
|
|
1072
|
-
partial: <T extends string | number | symbol, R
|
|
1073
|
-
withDefault: (defaultValue: R
|
|
1023
|
+
partial: <T extends string | number | symbol, R extends Type>(cases: Partial<Record<T, R | ((value: T) => R)>>) => {
|
|
1024
|
+
withDefault: (defaultValue: R | ((value: T) => R)) => (value: T) => R;
|
|
1074
1025
|
};
|
|
1075
1026
|
/**
|
|
1076
1027
|
* Pattern match with guards
|
|
@@ -1095,8 +1046,8 @@ declare const Match: (<T extends Type>(value: T) => UntypedMatch<T>) & {
|
|
|
1095
1046
|
* ]).withDefault("Unknown")(age)
|
|
1096
1047
|
* // category = "Adult (25 years)"
|
|
1097
1048
|
*/
|
|
1098
|
-
withGuards: <T extends Type, R
|
|
1099
|
-
withDefault: (defaultValue: R
|
|
1049
|
+
withGuards: <T extends Type, R extends Type>(guards: Array<[(value: T) => boolean, R | ((value: T) => R)]>) => {
|
|
1050
|
+
withDefault: (defaultValue: R | ((value: T) => R)) => (value: T) => R;
|
|
1100
1051
|
};
|
|
1101
1052
|
/**
|
|
1102
1053
|
* Pattern matching for objects with specific structure
|
|
@@ -1112,9 +1063,9 @@ declare const Match: (<T extends Type>(value: T) => UntypedMatch<T>) & {
|
|
|
1112
1063
|
* .case({ type: "hover" }, (e) => console.log(`Hovering over ${e.element}`))
|
|
1113
1064
|
* .build()
|
|
1114
1065
|
*/
|
|
1115
|
-
struct: <T extends Type, R
|
|
1116
|
-
case: (pattern: Pattern<T>, handler: (value: T) => R
|
|
1117
|
-
build: () => (value: T) => R
|
|
1066
|
+
struct: <T extends Type, R extends Type>() => {
|
|
1067
|
+
case: (pattern: Pattern<T>, handler: (value: T) => R) => /*elided*/any;
|
|
1068
|
+
build: () => (value: T) => R;
|
|
1118
1069
|
};
|
|
1119
1070
|
/**
|
|
1120
1071
|
* Create a pattern matcher with guards and nested patterns
|
|
@@ -1131,11 +1082,11 @@ declare const Match: (<T extends Type>(value: T) => UntypedMatch<T>) & {
|
|
|
1131
1082
|
* .default(false)
|
|
1132
1083
|
* .build()
|
|
1133
1084
|
*/
|
|
1134
|
-
builder: <T extends Type, R
|
|
1135
|
-
case: (pattern: Pattern<T>, result: PatternResult<T, R
|
|
1136
|
-
when: (guard: (value: T) => boolean, result: PatternResult<T, R
|
|
1137
|
-
default: (result: PatternResult<T, R
|
|
1138
|
-
build: () => (value: T) => R
|
|
1085
|
+
builder: <T extends Type, R extends Type>() => {
|
|
1086
|
+
case: (pattern: Pattern<T>, result: PatternResult<T, R>) => /*elided*/any;
|
|
1087
|
+
when: (guard: (value: T) => boolean, result: PatternResult<T, R>) => /*elided*/any;
|
|
1088
|
+
default: (result: PatternResult<T, R>) => {
|
|
1089
|
+
build: () => (value: T) => R;
|
|
1139
1090
|
};
|
|
1140
1091
|
};
|
|
1141
1092
|
};
|
|
@@ -1192,376 +1143,6 @@ declare class Throwable extends Error implements ThrowableType {
|
|
|
1192
1143
|
}): ThrowableType;
|
|
1193
1144
|
}
|
|
1194
1145
|
//#endregion
|
|
1195
|
-
//#region src/fpromise/FPromise.d.ts
|
|
1196
|
-
/**
|
|
1197
|
-
* Error context information that provides additional metadata about errors.
|
|
1198
|
-
* This context is passed to error mapping functions to provide more information
|
|
1199
|
-
* about the error that occurred.
|
|
1200
|
-
*
|
|
1201
|
-
* @property originalError - The original error that was thrown
|
|
1202
|
-
* @property stack - The stack trace of the error, if available
|
|
1203
|
-
* @property timestamp - The timestamp when the error occurred
|
|
1204
|
-
*/
|
|
1205
|
-
type ErrorContext = {
|
|
1206
|
-
originalError: unknown;
|
|
1207
|
-
stack?: string;
|
|
1208
|
-
timestamp: number;
|
|
1209
|
-
};
|
|
1210
|
-
/**
|
|
1211
|
-
* FPromise is a functional wrapper around JavaScript's Promise with enhanced error handling.
|
|
1212
|
-
* It implements the Functor and AsyncFunctor interfaces, providing map and flatMap operations
|
|
1213
|
-
* for functional composition.
|
|
1214
|
-
*
|
|
1215
|
-
* FPromise adds several features not available in standard Promises:
|
|
1216
|
-
* - Generic error typing for better type safety
|
|
1217
|
-
* - Error recovery mechanisms (recover, recoverWith, recoverWithF)
|
|
1218
|
-
* - Error filtering and categorization
|
|
1219
|
-
* - Side effect methods (tap, tapError)
|
|
1220
|
-
* - Error context preservation
|
|
1221
|
-
* - Conversion to/from Either for more functional error handling
|
|
1222
|
-
*
|
|
1223
|
-
* @template T - The type of the value that the FPromise resolves to
|
|
1224
|
-
* @template E - The type of the error that the FPromise may reject with (defaults to unknown)
|
|
1225
|
-
*/
|
|
1226
|
-
/**
|
|
1227
|
-
* FPromise type that defines the function signature and methods
|
|
1228
|
-
*/
|
|
1229
|
-
type FPromise<T extends Type, E extends Type = unknown> = PromiseLike<T> & {
|
|
1230
|
-
readonly _tag: "FPromise";
|
|
1231
|
-
tap: (f: (value: T) => void) => FPromise<T, E>;
|
|
1232
|
-
mapError: <E2>(f: (error: E, context: ErrorContext) => E2) => FPromise<T, E2>;
|
|
1233
|
-
tapError: (f: (error: E) => void) => FPromise<T, E>;
|
|
1234
|
-
recover: (fallback: T) => FPromise<T, never>;
|
|
1235
|
-
recoverWith: (f: (error: E) => T) => FPromise<T, never>;
|
|
1236
|
-
recoverWithF: <E2>(f: (error: E) => FPromise<T, E2>) => FPromise<T, E2>;
|
|
1237
|
-
filterError: <E2 extends E>(predicate: (error: E) => boolean, handler: (error: E) => FPromise<T, E2>) => FPromise<T, E>;
|
|
1238
|
-
logError: (logger: (error: E, context: ErrorContext) => void) => FPromise<T, E>;
|
|
1239
|
-
toPromise: () => Promise<T>;
|
|
1240
|
-
toEither: () => Promise<Either<E, T>>;
|
|
1241
|
-
fold: <R$1 extends Type>(onError: (error: E) => R$1, onSuccess: (value: T) => R$1) => FPromise<R$1, never>;
|
|
1242
|
-
map: <U extends Type>(f: (value: T) => U) => FPromise<U, E>;
|
|
1243
|
-
flatMap: <U extends Type>(f: (value: T) => FPromise<U, E> | PromiseLike<U>) => FPromise<U, E>;
|
|
1244
|
-
flatMapAsync: <U extends Type>(f: (value: T) => PromiseLike<U>) => Promise<U>;
|
|
1245
|
-
};
|
|
1246
|
-
/**
|
|
1247
|
-
* Static utility methods for FPromise using the Companion pattern.
|
|
1248
|
-
* These methods provide factory functions and utilities for working with FPromises.
|
|
1249
|
-
*/
|
|
1250
|
-
declare const FPromiseCompanion: {
|
|
1251
|
-
/**
|
|
1252
|
-
* Creates an FPromise that resolves to the provided value.
|
|
1253
|
-
*
|
|
1254
|
-
* @template T - The type of the value
|
|
1255
|
-
* @template E - The type of the error (defaults to never since this FPromise won't reject)
|
|
1256
|
-
* @param value - The value to resolve with
|
|
1257
|
-
* @returns An FPromise that resolves to the value
|
|
1258
|
-
*
|
|
1259
|
-
* @example
|
|
1260
|
-
* const promise = FPromise.resolve(42)
|
|
1261
|
-
* // promise resolves to 42
|
|
1262
|
-
*/
|
|
1263
|
-
resolve: <T, E = never>(value: T | PromiseLike<T>) => FPromise<T, E>;
|
|
1264
|
-
/**
|
|
1265
|
-
* Creates an FPromise that rejects with the provided reason.
|
|
1266
|
-
*
|
|
1267
|
-
* @template T - The type of the value (which will never be produced)
|
|
1268
|
-
* @template E - The type of the error
|
|
1269
|
-
* @param reason - The reason for rejection
|
|
1270
|
-
* @returns An FPromise that rejects with the reason
|
|
1271
|
-
*
|
|
1272
|
-
* @example
|
|
1273
|
-
* const promise = FPromise.reject<number, Error>(new Error("Something went wrong"))
|
|
1274
|
-
* // promise rejects with Error("Something went wrong")
|
|
1275
|
-
*/
|
|
1276
|
-
reject: <T, E = unknown>(reason: E) => FPromise<T, E>;
|
|
1277
|
-
/**
|
|
1278
|
-
* Creates an FPromise from a regular Promise.
|
|
1279
|
-
*
|
|
1280
|
-
* @template T - The type of the value
|
|
1281
|
-
* @template E - The type of the error
|
|
1282
|
-
* @param promise - The Promise to convert
|
|
1283
|
-
* @returns An FPromise that resolves or rejects with the same value or error
|
|
1284
|
-
*
|
|
1285
|
-
* @example
|
|
1286
|
-
* const promise = FPromise.from(fetch("https://api.example.com/data"))
|
|
1287
|
-
* // promise is an FPromise that resolves or rejects based on the fetch result
|
|
1288
|
-
*/
|
|
1289
|
-
from: <T, E = unknown>(promise: Promise<T>) => FPromise<T, E>;
|
|
1290
|
-
/**
|
|
1291
|
-
* Creates an FPromise from an Either.
|
|
1292
|
-
* If the Either is a Right, the FPromise resolves with the Right value.
|
|
1293
|
-
* If the Either is a Left, the FPromise rejects with the Left value.
|
|
1294
|
-
*
|
|
1295
|
-
* @template L - The type of the Left value (error)
|
|
1296
|
-
* @template R - The type of the Right value (success)
|
|
1297
|
-
* @param either - The Either to convert
|
|
1298
|
-
* @returns An FPromise that resolves or rejects based on the Either
|
|
1299
|
-
*
|
|
1300
|
-
* @example
|
|
1301
|
-
* const either = Right<Error, number>(42)
|
|
1302
|
-
* const promise = FPromise.fromEither(either)
|
|
1303
|
-
* // promise resolves to 42
|
|
1304
|
-
*/
|
|
1305
|
-
fromEither: <L, R$1>(either: Either<L, R$1>) => FPromise<R$1, L>;
|
|
1306
|
-
/**
|
|
1307
|
-
* Runs multiple FPromises in parallel and returns an array of results.
|
|
1308
|
-
* Similar to Promise.all, this will reject if any of the promises reject.
|
|
1309
|
-
*
|
|
1310
|
-
* @template T - The type of the values
|
|
1311
|
-
* @template E - The type of the error
|
|
1312
|
-
* @param promises - An array of FPromises, Promises, or values
|
|
1313
|
-
* @returns An FPromise that resolves to an array of results
|
|
1314
|
-
*
|
|
1315
|
-
* @example
|
|
1316
|
-
* const promises = [FPromise.resolve(1), FPromise.resolve(2), 3]
|
|
1317
|
-
* const result = await FPromise.all(promises).toPromise()
|
|
1318
|
-
* // result is [1, 2, 3]
|
|
1319
|
-
*/
|
|
1320
|
-
all: <T, E = unknown>(promises: Array<FPromise<T, E> | PromiseLike<T> | T>) => FPromise<T[], E>;
|
|
1321
|
-
/**
|
|
1322
|
-
* Like Promise.allSettled, returns results of all promises whether they succeed or fail.
|
|
1323
|
-
* This will always resolve, never reject.
|
|
1324
|
-
*
|
|
1325
|
-
* @template T - The type of the values
|
|
1326
|
-
* @template E - The type of the errors
|
|
1327
|
-
* @param promises - An array of FPromises or Promises
|
|
1328
|
-
* @returns An FPromise that resolves to an array of Either results
|
|
1329
|
-
*
|
|
1330
|
-
* @example
|
|
1331
|
-
* const promises = [FPromise.resolve(1), FPromise.reject<number, Error>(new Error("Failed"))]
|
|
1332
|
-
* const result = await FPromise.allSettled(promises).toPromise()
|
|
1333
|
-
* // result is [Right(1), Left(Error("Failed"))]
|
|
1334
|
-
*/
|
|
1335
|
-
allSettled: <T, E = unknown>(promises: Array<FPromise<T, E> | PromiseLike<T>>) => FPromise<Array<Either<E, T>>, never>;
|
|
1336
|
-
/**
|
|
1337
|
-
* Like Promise.race, returns the first promise to settle (either resolve or reject).
|
|
1338
|
-
*
|
|
1339
|
-
* @template T - The type of the values
|
|
1340
|
-
* @template E - The type of the errors
|
|
1341
|
-
* @param promises - An array of FPromises or Promises
|
|
1342
|
-
* @returns An FPromise that resolves or rejects with the result of the first promise to settle
|
|
1343
|
-
*
|
|
1344
|
-
* @example
|
|
1345
|
-
* const slow = FPromise.resolve(1).tap(() => new Promise(r => setTimeout(r, 100)))
|
|
1346
|
-
* const fast = FPromise.resolve(2).tap(() => new Promise(r => setTimeout(r, 50)))
|
|
1347
|
-
* const result = await FPromise.race([slow, fast]).toPromise()
|
|
1348
|
-
* // result is 2
|
|
1349
|
-
*/
|
|
1350
|
-
race: <T, E = unknown>(promises: Array<FPromise<T, E> | PromiseLike<T>>) => FPromise<T, E>;
|
|
1351
|
-
/**
|
|
1352
|
-
* Like Promise.any, returns the first promise to fulfill.
|
|
1353
|
-
* This will only reject if all promises reject.
|
|
1354
|
-
*
|
|
1355
|
-
* @template T - The type of the values
|
|
1356
|
-
* @template E - The type of the errors
|
|
1357
|
-
* @param promises - An array of FPromises or Promises
|
|
1358
|
-
* @returns An FPromise that resolves with the first promise to fulfill or rejects if all promises reject
|
|
1359
|
-
*
|
|
1360
|
-
* @example
|
|
1361
|
-
* const promises = [
|
|
1362
|
-
* FPromise.reject<number, Error>(new Error("First failed")),
|
|
1363
|
-
* FPromise.resolve(2),
|
|
1364
|
-
* FPromise.reject<number, Error>(new Error("Third failed"))
|
|
1365
|
-
* ]
|
|
1366
|
-
* const result = await FPromise.any(promises).toPromise()
|
|
1367
|
-
* // result is 2
|
|
1368
|
-
*/
|
|
1369
|
-
any: <T, E = unknown>(promises: Array<FPromise<T, E> | PromiseLike<T>>) => FPromise<T, E>;
|
|
1370
|
-
/**
|
|
1371
|
-
* Retries an operation with exponential backoff.
|
|
1372
|
-
* This is useful for operations that may fail temporarily, such as network requests.
|
|
1373
|
-
*
|
|
1374
|
-
* @template T - The type of the value
|
|
1375
|
-
* @template E - The type of the error
|
|
1376
|
-
* @param operation - A function that returns an FPromise
|
|
1377
|
-
* @param options - Configuration options for the retry
|
|
1378
|
-
* @param options.maxRetries - Maximum number of retry attempts
|
|
1379
|
-
* @param options.baseDelay - Base delay in milliseconds (default: 100)
|
|
1380
|
-
* @param options.shouldRetry - Function that determines whether to retry based on the error (default: always retry)
|
|
1381
|
-
* @returns An FPromise that resolves when the operation succeeds or rejects after all retries fail
|
|
1382
|
-
*
|
|
1383
|
-
* @example
|
|
1384
|
-
* const operation = () => {
|
|
1385
|
-
* if (Math.random() > 0.8) {
|
|
1386
|
-
* return FPromise.resolve("Success!")
|
|
1387
|
-
* }
|
|
1388
|
-
* return FPromise.reject<string, Error>(new Error("Temporary failure"))
|
|
1389
|
-
* }
|
|
1390
|
-
*
|
|
1391
|
-
* const result = await FPromise.retryWithBackoff(operation, {
|
|
1392
|
-
* maxRetries: 3,
|
|
1393
|
-
* baseDelay: 100,
|
|
1394
|
-
* shouldRetry: (error) => error.message === "Temporary failure"
|
|
1395
|
-
* }).toPromise()
|
|
1396
|
-
*/
|
|
1397
|
-
retryWithBackoff: <T, E = unknown>(operation: () => FPromise<T, E>, options: {
|
|
1398
|
-
maxRetries: number;
|
|
1399
|
-
baseDelay?: number;
|
|
1400
|
-
shouldRetry?: (error: E, attempt: number) => boolean;
|
|
1401
|
-
}) => FPromise<T, E>;
|
|
1402
|
-
};
|
|
1403
|
-
/**
|
|
1404
|
-
* Creates an FPromise from an executor function.
|
|
1405
|
-
*
|
|
1406
|
-
* @template T - The type of the value that the FPromise resolves to
|
|
1407
|
-
* @template E - The type of the error that the FPromise may reject with
|
|
1408
|
-
* @param executor - A function that receives resolve and reject functions
|
|
1409
|
-
* @returns An FPromise instance
|
|
1410
|
-
*/
|
|
1411
|
-
declare const FPromise: (<T extends Type, E = unknown>(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: E) => void) => void) => FPromise<T, E>) & {
|
|
1412
|
-
/**
|
|
1413
|
-
* Creates an FPromise that resolves to the provided value.
|
|
1414
|
-
*
|
|
1415
|
-
* @template T - The type of the value
|
|
1416
|
-
* @template E - The type of the error (defaults to never since this FPromise won't reject)
|
|
1417
|
-
* @param value - The value to resolve with
|
|
1418
|
-
* @returns An FPromise that resolves to the value
|
|
1419
|
-
*
|
|
1420
|
-
* @example
|
|
1421
|
-
* const promise = FPromise.resolve(42)
|
|
1422
|
-
* // promise resolves to 42
|
|
1423
|
-
*/
|
|
1424
|
-
resolve: <T, E = never>(value: T | PromiseLike<T>) => FPromise<T, E>;
|
|
1425
|
-
/**
|
|
1426
|
-
* Creates an FPromise that rejects with the provided reason.
|
|
1427
|
-
*
|
|
1428
|
-
* @template T - The type of the value (which will never be produced)
|
|
1429
|
-
* @template E - The type of the error
|
|
1430
|
-
* @param reason - The reason for rejection
|
|
1431
|
-
* @returns An FPromise that rejects with the reason
|
|
1432
|
-
*
|
|
1433
|
-
* @example
|
|
1434
|
-
* const promise = FPromise.reject<number, Error>(new Error("Something went wrong"))
|
|
1435
|
-
* // promise rejects with Error("Something went wrong")
|
|
1436
|
-
*/
|
|
1437
|
-
reject: <T, E = unknown>(reason: E) => FPromise<T, E>;
|
|
1438
|
-
/**
|
|
1439
|
-
* Creates an FPromise from a regular Promise.
|
|
1440
|
-
*
|
|
1441
|
-
* @template T - The type of the value
|
|
1442
|
-
* @template E - The type of the error
|
|
1443
|
-
* @param promise - The Promise to convert
|
|
1444
|
-
* @returns An FPromise that resolves or rejects with the same value or error
|
|
1445
|
-
*
|
|
1446
|
-
* @example
|
|
1447
|
-
* const promise = FPromise.from(fetch("https://api.example.com/data"))
|
|
1448
|
-
* // promise is an FPromise that resolves or rejects based on the fetch result
|
|
1449
|
-
*/
|
|
1450
|
-
from: <T, E = unknown>(promise: Promise<T>) => FPromise<T, E>;
|
|
1451
|
-
/**
|
|
1452
|
-
* Creates an FPromise from an Either.
|
|
1453
|
-
* If the Either is a Right, the FPromise resolves with the Right value.
|
|
1454
|
-
* If the Either is a Left, the FPromise rejects with the Left value.
|
|
1455
|
-
*
|
|
1456
|
-
* @template L - The type of the Left value (error)
|
|
1457
|
-
* @template R - The type of the Right value (success)
|
|
1458
|
-
* @param either - The Either to convert
|
|
1459
|
-
* @returns An FPromise that resolves or rejects based on the Either
|
|
1460
|
-
*
|
|
1461
|
-
* @example
|
|
1462
|
-
* const either = Right<Error, number>(42)
|
|
1463
|
-
* const promise = FPromise.fromEither(either)
|
|
1464
|
-
* // promise resolves to 42
|
|
1465
|
-
*/
|
|
1466
|
-
fromEither: <L, R$1>(either: Either<L, R$1>) => FPromise<R$1, L>;
|
|
1467
|
-
/**
|
|
1468
|
-
* Runs multiple FPromises in parallel and returns an array of results.
|
|
1469
|
-
* Similar to Promise.all, this will reject if any of the promises reject.
|
|
1470
|
-
*
|
|
1471
|
-
* @template T - The type of the values
|
|
1472
|
-
* @template E - The type of the error
|
|
1473
|
-
* @param promises - An array of FPromises, Promises, or values
|
|
1474
|
-
* @returns An FPromise that resolves to an array of results
|
|
1475
|
-
*
|
|
1476
|
-
* @example
|
|
1477
|
-
* const promises = [FPromise.resolve(1), FPromise.resolve(2), 3]
|
|
1478
|
-
* const result = await FPromise.all(promises).toPromise()
|
|
1479
|
-
* // result is [1, 2, 3]
|
|
1480
|
-
*/
|
|
1481
|
-
all: <T, E = unknown>(promises: Array<FPromise<T, E> | PromiseLike<T> | T>) => FPromise<T[], E>;
|
|
1482
|
-
/**
|
|
1483
|
-
* Like Promise.allSettled, returns results of all promises whether they succeed or fail.
|
|
1484
|
-
* This will always resolve, never reject.
|
|
1485
|
-
*
|
|
1486
|
-
* @template T - The type of the values
|
|
1487
|
-
* @template E - The type of the errors
|
|
1488
|
-
* @param promises - An array of FPromises or Promises
|
|
1489
|
-
* @returns An FPromise that resolves to an array of Either results
|
|
1490
|
-
*
|
|
1491
|
-
* @example
|
|
1492
|
-
* const promises = [FPromise.resolve(1), FPromise.reject<number, Error>(new Error("Failed"))]
|
|
1493
|
-
* const result = await FPromise.allSettled(promises).toPromise()
|
|
1494
|
-
* // result is [Right(1), Left(Error("Failed"))]
|
|
1495
|
-
*/
|
|
1496
|
-
allSettled: <T, E = unknown>(promises: Array<FPromise<T, E> | PromiseLike<T>>) => FPromise<Array<Either<E, T>>, never>;
|
|
1497
|
-
/**
|
|
1498
|
-
* Like Promise.race, returns the first promise to settle (either resolve or reject).
|
|
1499
|
-
*
|
|
1500
|
-
* @template T - The type of the values
|
|
1501
|
-
* @template E - The type of the errors
|
|
1502
|
-
* @param promises - An array of FPromises or Promises
|
|
1503
|
-
* @returns An FPromise that resolves or rejects with the result of the first promise to settle
|
|
1504
|
-
*
|
|
1505
|
-
* @example
|
|
1506
|
-
* const slow = FPromise.resolve(1).tap(() => new Promise(r => setTimeout(r, 100)))
|
|
1507
|
-
* const fast = FPromise.resolve(2).tap(() => new Promise(r => setTimeout(r, 50)))
|
|
1508
|
-
* const result = await FPromise.race([slow, fast]).toPromise()
|
|
1509
|
-
* // result is 2
|
|
1510
|
-
*/
|
|
1511
|
-
race: <T, E = unknown>(promises: Array<FPromise<T, E> | PromiseLike<T>>) => FPromise<T, E>;
|
|
1512
|
-
/**
|
|
1513
|
-
* Like Promise.any, returns the first promise to fulfill.
|
|
1514
|
-
* This will only reject if all promises reject.
|
|
1515
|
-
*
|
|
1516
|
-
* @template T - The type of the values
|
|
1517
|
-
* @template E - The type of the errors
|
|
1518
|
-
* @param promises - An array of FPromises or Promises
|
|
1519
|
-
* @returns An FPromise that resolves with the first promise to fulfill or rejects if all promises reject
|
|
1520
|
-
*
|
|
1521
|
-
* @example
|
|
1522
|
-
* const promises = [
|
|
1523
|
-
* FPromise.reject<number, Error>(new Error("First failed")),
|
|
1524
|
-
* FPromise.resolve(2),
|
|
1525
|
-
* FPromise.reject<number, Error>(new Error("Third failed"))
|
|
1526
|
-
* ]
|
|
1527
|
-
* const result = await FPromise.any(promises).toPromise()
|
|
1528
|
-
* // result is 2
|
|
1529
|
-
*/
|
|
1530
|
-
any: <T, E = unknown>(promises: Array<FPromise<T, E> | PromiseLike<T>>) => FPromise<T, E>;
|
|
1531
|
-
/**
|
|
1532
|
-
* Retries an operation with exponential backoff.
|
|
1533
|
-
* This is useful for operations that may fail temporarily, such as network requests.
|
|
1534
|
-
*
|
|
1535
|
-
* @template T - The type of the value
|
|
1536
|
-
* @template E - The type of the error
|
|
1537
|
-
* @param operation - A function that returns an FPromise
|
|
1538
|
-
* @param options - Configuration options for the retry
|
|
1539
|
-
* @param options.maxRetries - Maximum number of retry attempts
|
|
1540
|
-
* @param options.baseDelay - Base delay in milliseconds (default: 100)
|
|
1541
|
-
* @param options.shouldRetry - Function that determines whether to retry based on the error (default: always retry)
|
|
1542
|
-
* @returns An FPromise that resolves when the operation succeeds or rejects after all retries fail
|
|
1543
|
-
*
|
|
1544
|
-
* @example
|
|
1545
|
-
* const operation = () => {
|
|
1546
|
-
* if (Math.random() > 0.8) {
|
|
1547
|
-
* return FPromise.resolve("Success!")
|
|
1548
|
-
* }
|
|
1549
|
-
* return FPromise.reject<string, Error>(new Error("Temporary failure"))
|
|
1550
|
-
* }
|
|
1551
|
-
*
|
|
1552
|
-
* const result = await FPromise.retryWithBackoff(operation, {
|
|
1553
|
-
* maxRetries: 3,
|
|
1554
|
-
* baseDelay: 100,
|
|
1555
|
-
* shouldRetry: (error) => error.message === "Temporary failure"
|
|
1556
|
-
* }).toPromise()
|
|
1557
|
-
*/
|
|
1558
|
-
retryWithBackoff: <T, E = unknown>(operation: () => FPromise<T, E>, options: {
|
|
1559
|
-
maxRetries: number;
|
|
1560
|
-
baseDelay?: number;
|
|
1561
|
-
shouldRetry?: (error: E, attempt: number) => boolean;
|
|
1562
|
-
}) => FPromise<T, E>;
|
|
1563
|
-
};
|
|
1564
|
-
//#endregion
|
|
1565
1146
|
//#region src/core/task/Task.d.ts
|
|
1566
1147
|
/**
|
|
1567
1148
|
* Type definition for errors with a _tag property that identifies them as Throwables
|
|
@@ -1644,11 +1225,8 @@ type TaskResult<T> = Promise<TaskOutcome<T>>;
|
|
|
1644
1225
|
* Cancellation is cooperative, meaning the task must check the token and respond to cancellation requests
|
|
1645
1226
|
*/
|
|
1646
1227
|
type CancellationToken = {
|
|
1647
|
-
/** Whether the token has been cancelled */
|
|
1648
|
-
readonly
|
|
1649
|
-
/** Signal that can be used with fetch and other abortable APIs */
|
|
1650
|
-
readonly signal: AbortSignal;
|
|
1651
|
-
/** Register a callback to be called when cancellation occurs */
|
|
1228
|
+
/** Whether the token has been cancelled */readonly isCancelled: boolean; /** Signal that can be used with fetch and other abortable APIs */
|
|
1229
|
+
readonly signal: AbortSignal; /** Register a callback to be called when cancellation occurs */
|
|
1652
1230
|
onCancel(callback: () => void): void;
|
|
1653
1231
|
};
|
|
1654
1232
|
/**
|
|
@@ -1656,9 +1234,7 @@ type CancellationToken = {
|
|
|
1656
1234
|
* The controller can be used to cancel operations that use the token
|
|
1657
1235
|
*/
|
|
1658
1236
|
type CancellationTokenSource = {
|
|
1659
|
-
/** The token to be passed to cancellable operations */
|
|
1660
|
-
readonly token: CancellationToken;
|
|
1661
|
-
/** Cancel all operations using this token */
|
|
1237
|
+
/** The token to be passed to cancellable operations */readonly token: CancellationToken; /** Cancel all operations using this token */
|
|
1662
1238
|
cancel(): void;
|
|
1663
1239
|
};
|
|
1664
1240
|
/**
|
|
@@ -1679,7 +1255,7 @@ declare const Task$1: (<T = unknown>(params?: TaskParams) => {
|
|
|
1679
1255
|
* @param f - Optional finally handler function
|
|
1680
1256
|
* @param cancellationToken - Optional token for cancellation support
|
|
1681
1257
|
*/
|
|
1682
|
-
Async: <U = T>(t: () => U | Promise<U> | TaskOutcome<U> | Promise<TaskOutcome<U>>, e?: (error: unknown) => unknown | TaskOutcome<U>, f?: () => Promise<void> | void, cancellationToken?: CancellationToken) =>
|
|
1258
|
+
Async: <U = T>(t: () => U | Promise<U> | TaskOutcome<U> | Promise<TaskOutcome<U>>, e?: (error: unknown) => unknown | TaskOutcome<U>, f?: () => Promise<void> | void, cancellationToken?: CancellationToken) => Promise<TaskOutcome<U>>;
|
|
1683
1259
|
/**
|
|
1684
1260
|
* Run a synchronous operation with explicit try/catch/finally semantics
|
|
1685
1261
|
* Returns a TaskOutcome for functional error handling
|
|
@@ -1699,7 +1275,7 @@ declare const Task$1: (<T = unknown>(params?: TaskParams) => {
|
|
|
1699
1275
|
* @param f - Optional finally handler function
|
|
1700
1276
|
* @param cancellationToken - Optional token for cancellation support
|
|
1701
1277
|
*/
|
|
1702
|
-
AsyncWithProgress: <U = T>(t: (updateProgress: (percent: number) => void) => U | Promise<U> | TaskOutcome<U> | Promise<TaskOutcome<U>>, onProgress: (percent: number) => void, e?: (error: unknown) => unknown | TaskOutcome<U>, f?: () => Promise<void> | void, cancellationToken?: CancellationToken) =>
|
|
1278
|
+
AsyncWithProgress: <U = T>(t: (updateProgress: (percent: number) => void) => U | Promise<U> | TaskOutcome<U> | Promise<TaskOutcome<U>>, onProgress: (percent: number) => void, e?: (error: unknown) => unknown | TaskOutcome<U>, f?: () => Promise<void> | void, cancellationToken?: CancellationToken) => Promise<TaskOutcome<U>>;
|
|
1703
1279
|
toString(): string;
|
|
1704
1280
|
doUnwrap(): DoResult<unknown>;
|
|
1705
1281
|
_tag: string;
|
|
@@ -1757,7 +1333,7 @@ declare const Task$1: (<T = unknown>(params?: TaskParams) => {
|
|
|
1757
1333
|
/**
|
|
1758
1334
|
* Convert a Promise-returning function to a Task-compatible function
|
|
1759
1335
|
*/
|
|
1760
|
-
fromPromise: <U, Args extends unknown[]>(promiseFn: (...args: Args) => Promise<U>, params?: TaskParams) => ((...args: Args) =>
|
|
1336
|
+
fromPromise: <U, Args extends unknown[]>(promiseFn: (...args: Args) => Promise<U>, params?: TaskParams) => ((...args: Args) => Promise<TaskOutcome<U>>);
|
|
1761
1337
|
/**
|
|
1762
1338
|
* Convert a Task result to a Promise
|
|
1763
1339
|
*/
|
|
@@ -1766,21 +1342,21 @@ declare const Task$1: (<T = unknown>(params?: TaskParams) => {
|
|
|
1766
1342
|
* Race multiple tasks and return the result of the first one to complete
|
|
1767
1343
|
* Optionally specify a timeout after which the race will fail
|
|
1768
1344
|
*
|
|
1769
|
-
* @param tasks - Array of tasks to race (as
|
|
1345
|
+
* @param tasks - Array of tasks to race (as Promises)
|
|
1770
1346
|
* @param timeoutMs - Optional timeout in milliseconds
|
|
1771
1347
|
* @param params - Task parameters for the race operation
|
|
1772
1348
|
* @returns A promise that resolves with the first task to complete or rejects if all tasks fail
|
|
1773
1349
|
*/
|
|
1774
|
-
race: <T>(tasks: Array<
|
|
1350
|
+
race: <T>(tasks: Array<Promise<T> | Promise<TaskOutcome<T>>>, timeoutMs?: number, params?: TaskParams) => Promise<TaskOutcome<T>>;
|
|
1775
1351
|
/**
|
|
1776
1352
|
* Convert a Node.js style callback function to a Task-compatible function
|
|
1777
1353
|
* Node.js callbacks typically have the signature (error, result) => void
|
|
1778
1354
|
*
|
|
1779
1355
|
* @param nodeFn - Function that accepts a Node.js style callback
|
|
1780
1356
|
* @param params - Task parameters
|
|
1781
|
-
* @returns A function that returns
|
|
1357
|
+
* @returns A function that returns a Promise
|
|
1782
1358
|
*/
|
|
1783
|
-
fromNodeCallback: <T, Args extends unknown[]>(nodeFn: (...args: [...Args, (error: unknown, result: T) => void]) => void, params?: TaskParams) => ((...args: Args) =>
|
|
1359
|
+
fromNodeCallback: <T, Args extends unknown[]>(nodeFn: (...args: [...Args, (error: unknown, result: T) => void]) => void, params?: TaskParams) => ((...args: Args) => Promise<TaskOutcome<T>>);
|
|
1784
1360
|
/**
|
|
1785
1361
|
* Create a cancellation token source
|
|
1786
1362
|
* @returns A cancellation token source that can be used to control task cancellation
|
|
@@ -1794,7 +1370,7 @@ declare const Task$1: (<T = unknown>(params?: TaskParams) => {
|
|
|
1794
1370
|
* @returns An object with the task and a function to cancel it
|
|
1795
1371
|
*/
|
|
1796
1372
|
cancellable: <T>(task: (token: CancellationToken) => Promise<T> | Promise<TaskOutcome<T>>, params?: TaskParams) => {
|
|
1797
|
-
task:
|
|
1373
|
+
task: Promise<TaskOutcome<T>>;
|
|
1798
1374
|
cancel: () => void;
|
|
1799
1375
|
};
|
|
1800
1376
|
/**
|
|
@@ -1806,7 +1382,7 @@ declare const Task$1: (<T = unknown>(params?: TaskParams) => {
|
|
|
1806
1382
|
* @returns An object with the task, cancel function, and current progress
|
|
1807
1383
|
*/
|
|
1808
1384
|
withProgress: <T>(task: (updateProgress: (percent: number) => void, token: CancellationToken) => Promise<T> | Promise<TaskOutcome<T>>, onProgress?: (percent: number) => void, params?: TaskParams) => {
|
|
1809
|
-
task:
|
|
1385
|
+
task: Promise<TaskOutcome<T>>;
|
|
1810
1386
|
cancel: () => void;
|
|
1811
1387
|
currentProgress: () => number;
|
|
1812
1388
|
};
|
|
@@ -1843,19 +1419,12 @@ type ErrorChainElement = {
|
|
|
1843
1419
|
* Options for formatting error chains
|
|
1844
1420
|
*/
|
|
1845
1421
|
type ErrorFormatterOptions = {
|
|
1846
|
-
/** Include task names in the formatted output */
|
|
1847
|
-
|
|
1848
|
-
/** Include
|
|
1849
|
-
|
|
1850
|
-
/**
|
|
1851
|
-
|
|
1852
|
-
/** Include detailed error data in the output */
|
|
1853
|
-
includeData?: boolean;
|
|
1854
|
-
/** Maximum number of stack frames to include if stack trace is enabled */
|
|
1855
|
-
maxStackFrames?: number;
|
|
1856
|
-
/** Title to display at the start of the formatted error */
|
|
1857
|
-
title?: string;
|
|
1858
|
-
/** Format the output with colors for console display */
|
|
1422
|
+
/** Include task names in the formatted output */includeTasks?: boolean; /** Include stack traces in the formatted output */
|
|
1423
|
+
includeStackTrace?: boolean; /** Separator between error lines (default: newline) */
|
|
1424
|
+
separator?: string; /** Include detailed error data in the output */
|
|
1425
|
+
includeData?: boolean; /** Maximum number of stack frames to include if stack trace is enabled */
|
|
1426
|
+
maxStackFrames?: number; /** Title to display at the start of the formatted error */
|
|
1427
|
+
title?: string; /** Format the output with colors for console display */
|
|
1859
1428
|
colors?: boolean;
|
|
1860
1429
|
};
|
|
1861
1430
|
/**
|
|
@@ -2332,7 +1901,7 @@ type TagService<T> = T extends Tag<infer S> ? S : never;
|
|
|
2332
1901
|
* const loggerUnsafe = ctx.unsafeGet(Logger) // Logger (throws if missing)
|
|
2333
1902
|
* ```
|
|
2334
1903
|
*/
|
|
2335
|
-
interface Context<R
|
|
1904
|
+
interface Context<R extends Type> {
|
|
2336
1905
|
/**
|
|
2337
1906
|
* Type brand
|
|
2338
1907
|
* @internal
|
|
@@ -2342,7 +1911,7 @@ interface Context<R$1 extends Type> {
|
|
|
2342
1911
|
* Phantom type for requirements
|
|
2343
1912
|
* @internal
|
|
2344
1913
|
*/
|
|
2345
|
-
readonly _R?: R
|
|
1914
|
+
readonly _R?: R;
|
|
2346
1915
|
/**
|
|
2347
1916
|
* Internal service map
|
|
2348
1917
|
* @internal
|
|
@@ -2373,13 +1942,13 @@ interface Context<R$1 extends Type> {
|
|
|
2373
1942
|
* @param service - The service implementation
|
|
2374
1943
|
* @returns A new context with the service added
|
|
2375
1944
|
*/
|
|
2376
|
-
add<S extends Type>(tag: Tag<S>, service: S): Context<R
|
|
1945
|
+
add<S extends Type>(tag: Tag<S>, service: S): Context<R & S>;
|
|
2377
1946
|
/**
|
|
2378
1947
|
* Merges another context into this one.
|
|
2379
1948
|
* @param other - The context to merge
|
|
2380
1949
|
* @returns A new context with all services from both
|
|
2381
1950
|
*/
|
|
2382
|
-
merge<R2 extends Type>(other: Context<R2>): Context<R
|
|
1951
|
+
merge<R2 extends Type>(other: Context<R2>): Context<R & R2>;
|
|
2383
1952
|
/**
|
|
2384
1953
|
* Returns the number of services in this context.
|
|
2385
1954
|
*/
|
|
@@ -2396,7 +1965,7 @@ declare const Context: {
|
|
|
2396
1965
|
/**
|
|
2397
1966
|
* Creates an empty context with no services.
|
|
2398
1967
|
*/
|
|
2399
|
-
empty: <R
|
|
1968
|
+
empty: <R extends Type = never>() => Context<R>;
|
|
2400
1969
|
/**
|
|
2401
1970
|
* Creates a context with a single service.
|
|
2402
1971
|
* @param tag - The tag for the service
|
|
@@ -2406,7 +1975,7 @@ declare const Context: {
|
|
|
2406
1975
|
/**
|
|
2407
1976
|
* Checks if a value is a Context.
|
|
2408
1977
|
*/
|
|
2409
|
-
isContext: <R
|
|
1978
|
+
isContext: <R extends Type>(value: unknown) => value is Context<R>;
|
|
2410
1979
|
};
|
|
2411
1980
|
/**
|
|
2412
1981
|
* Type helper to extract requirements from a Context
|
|
@@ -2702,7 +2271,7 @@ declare const Layer: {
|
|
|
2702
2271
|
* Creates a layer from a context.
|
|
2703
2272
|
* @param context - The context to use
|
|
2704
2273
|
*/
|
|
2705
|
-
fromContext: <R
|
|
2274
|
+
fromContext: <R extends Type>(context: Context<R>) => Layer<never, never, R>;
|
|
2706
2275
|
/**
|
|
2707
2276
|
* Creates an empty layer that provides nothing.
|
|
2708
2277
|
*/
|
|
@@ -2761,7 +2330,7 @@ declare class InterruptedError extends Error {
|
|
|
2761
2330
|
/**
|
|
2762
2331
|
* Internal effect representation types
|
|
2763
2332
|
*/
|
|
2764
|
-
type IOEffect<R
|
|
2333
|
+
type IOEffect<R, E, A> = {
|
|
2765
2334
|
readonly _tag: "Sync";
|
|
2766
2335
|
readonly thunk: () => A;
|
|
2767
2336
|
} | {
|
|
@@ -2783,48 +2352,48 @@ type IOEffect<R$1, E, A> = {
|
|
|
2783
2352
|
readonly _tag: "Interrupt";
|
|
2784
2353
|
} | {
|
|
2785
2354
|
readonly _tag: "FlatMap";
|
|
2786
|
-
readonly effect: IO<R
|
|
2787
|
-
readonly f: (a: unknown) => IO<R
|
|
2355
|
+
readonly effect: IO<R, E, unknown>;
|
|
2356
|
+
readonly f: (a: unknown) => IO<R, E, A>;
|
|
2788
2357
|
} | {
|
|
2789
2358
|
readonly _tag: "Map";
|
|
2790
|
-
readonly effect: IO<R
|
|
2359
|
+
readonly effect: IO<R, E, unknown>;
|
|
2791
2360
|
readonly f: (a: unknown) => A;
|
|
2792
2361
|
} | {
|
|
2793
2362
|
readonly _tag: "MapError";
|
|
2794
|
-
readonly effect: IO<R
|
|
2363
|
+
readonly effect: IO<R, unknown, A>;
|
|
2795
2364
|
readonly f: (e: unknown) => E;
|
|
2796
2365
|
} | {
|
|
2797
2366
|
readonly _tag: "Recover";
|
|
2798
|
-
readonly effect: IO<R
|
|
2367
|
+
readonly effect: IO<R, E, A>;
|
|
2799
2368
|
readonly fallback: A;
|
|
2800
2369
|
} | {
|
|
2801
2370
|
readonly _tag: "RecoverWith";
|
|
2802
|
-
readonly effect: IO<R
|
|
2803
|
-
readonly f: (e: E) => IO<R
|
|
2371
|
+
readonly effect: IO<R, E, A>;
|
|
2372
|
+
readonly f: (e: E) => IO<R, E, A>;
|
|
2804
2373
|
} | {
|
|
2805
2374
|
readonly _tag: "Fold";
|
|
2806
|
-
readonly effect: IO<R
|
|
2375
|
+
readonly effect: IO<R, E, unknown>;
|
|
2807
2376
|
readonly onFailure: (e: E) => A;
|
|
2808
2377
|
readonly onSuccess: (a: unknown) => A;
|
|
2809
2378
|
} | {
|
|
2810
2379
|
readonly _tag: "Bracket";
|
|
2811
|
-
readonly acquire: IO<R
|
|
2812
|
-
readonly use: (a: unknown) => IO<R
|
|
2813
|
-
readonly release: (a: unknown) => IO<R
|
|
2380
|
+
readonly acquire: IO<R, E, unknown>;
|
|
2381
|
+
readonly use: (a: unknown) => IO<R, E, A>;
|
|
2382
|
+
readonly release: (a: unknown) => IO<R, never, void>;
|
|
2814
2383
|
} | {
|
|
2815
2384
|
readonly _tag: "Race";
|
|
2816
|
-
readonly effects: readonly IO<R
|
|
2385
|
+
readonly effects: readonly IO<R, E, A>[];
|
|
2817
2386
|
} | {
|
|
2818
2387
|
readonly _tag: "Timeout";
|
|
2819
|
-
readonly effect: IO<R
|
|
2388
|
+
readonly effect: IO<R, E, A>;
|
|
2820
2389
|
readonly duration: number;
|
|
2821
2390
|
} | {
|
|
2822
2391
|
readonly _tag: "Service";
|
|
2823
2392
|
readonly tag: Tag<A>;
|
|
2824
2393
|
} | {
|
|
2825
2394
|
readonly _tag: "ProvideContext";
|
|
2826
|
-
readonly effect: IO<R
|
|
2827
|
-
readonly context: Context<R
|
|
2395
|
+
readonly effect: IO<R, E, A>;
|
|
2396
|
+
readonly context: Context<R>;
|
|
2828
2397
|
};
|
|
2829
2398
|
/**
|
|
2830
2399
|
* IO<R, E, A> represents a lazy, composable effect.
|
|
@@ -2833,17 +2402,17 @@ type IOEffect<R$1, E, A> = {
|
|
|
2833
2402
|
* @typeParam E - Error type (typed failures)
|
|
2834
2403
|
* @typeParam A - Success type (value produced on success)
|
|
2835
2404
|
*/
|
|
2836
|
-
interface IO<R
|
|
2405
|
+
interface IO<R extends Type, E extends Type, A extends Type> {
|
|
2837
2406
|
/**
|
|
2838
2407
|
* Internal effect representation
|
|
2839
2408
|
* @internal
|
|
2840
2409
|
*/
|
|
2841
|
-
readonly _effect: IOEffect<R
|
|
2410
|
+
readonly _effect: IOEffect<R, E, A>;
|
|
2842
2411
|
/**
|
|
2843
2412
|
* Phantom type for requirements
|
|
2844
2413
|
* @internal
|
|
2845
2414
|
*/
|
|
2846
|
-
readonly _R?: R
|
|
2415
|
+
readonly _R?: R;
|
|
2847
2416
|
/**
|
|
2848
2417
|
* Phantom type for error
|
|
2849
2418
|
* @internal
|
|
@@ -2859,31 +2428,31 @@ interface IO<R$1 extends Type, E extends Type, A extends Type> {
|
|
|
2859
2428
|
* @param f - Function to apply to the success value
|
|
2860
2429
|
* @returns New IO with transformed value
|
|
2861
2430
|
*/
|
|
2862
|
-
map<B extends Type>(f: (a: A) => B): IO<R
|
|
2431
|
+
map<B extends Type>(f: (a: A) => B): IO<R, E, B>;
|
|
2863
2432
|
/**
|
|
2864
2433
|
* Chains another IO effect based on the success value.
|
|
2865
2434
|
* @param f - Function returning next IO effect
|
|
2866
2435
|
* @returns New IO with combined effects
|
|
2867
2436
|
*/
|
|
2868
|
-
flatMap<R2 extends Type, E2 extends Type, B extends Type>(f: (a: A) => IO<R2, E2, B>): IO<R
|
|
2437
|
+
flatMap<R2 extends Type, E2 extends Type, B extends Type>(f: (a: A) => IO<R2, E2, B>): IO<R | R2, E | E2, B>;
|
|
2869
2438
|
/**
|
|
2870
2439
|
* Applies a side effect without changing the value.
|
|
2871
2440
|
* @param f - Side effect function
|
|
2872
2441
|
* @returns Same IO for chaining
|
|
2873
2442
|
*/
|
|
2874
|
-
tap(f: (a: A) => void): IO<R
|
|
2443
|
+
tap(f: (a: A) => void): IO<R, E, A>;
|
|
2875
2444
|
/**
|
|
2876
2445
|
* Applies an effectful side effect without changing the value.
|
|
2877
2446
|
* @param f - Function returning IO for side effect
|
|
2878
2447
|
* @returns Same value after running side effect
|
|
2879
2448
|
*/
|
|
2880
|
-
tapEffect<R2 extends Type, E2 extends Type, B extends Type>(f: (a: A) => IO<R2, E2, B>): IO<R
|
|
2449
|
+
tapEffect<R2 extends Type, E2 extends Type, B extends Type>(f: (a: A) => IO<R2, E2, B>): IO<R | R2, E | E2, A>;
|
|
2881
2450
|
/**
|
|
2882
2451
|
* Transforms the error value.
|
|
2883
2452
|
* @param f - Function to apply to the error
|
|
2884
2453
|
* @returns New IO with transformed error
|
|
2885
2454
|
*/
|
|
2886
|
-
mapError<E2 extends Type>(f: (e: E) => E2): IO<R
|
|
2455
|
+
mapError<E2 extends Type>(f: (e: E) => E2): IO<R, E2, A>;
|
|
2887
2456
|
/**
|
|
2888
2457
|
* Executes a side effect on the error without changing it.
|
|
2889
2458
|
* Useful for logging errors while preserving the error chain.
|
|
@@ -2898,92 +2467,92 @@ interface IO<R$1 extends Type, E extends Type, A extends Type> {
|
|
|
2898
2467
|
* .map(data => transform(data))
|
|
2899
2468
|
* ```
|
|
2900
2469
|
*/
|
|
2901
|
-
tapError(f: (e: E) => void): IO<R
|
|
2470
|
+
tapError(f: (e: E) => void): IO<R, E, A>;
|
|
2902
2471
|
/**
|
|
2903
2472
|
* Recovers from any error with a fallback value.
|
|
2904
2473
|
* @param fallback - Value to use on error
|
|
2905
2474
|
* @returns New IO that never fails
|
|
2906
2475
|
*/
|
|
2907
|
-
recover<B extends Type>(fallback: B): IO<R
|
|
2476
|
+
recover<B extends Type>(fallback: B): IO<R, never, A | B>;
|
|
2908
2477
|
/**
|
|
2909
2478
|
* Recovers from error by running another effect.
|
|
2910
2479
|
* @param f - Function returning recovery effect
|
|
2911
2480
|
* @returns New IO with error handling
|
|
2912
2481
|
*/
|
|
2913
|
-
recoverWith<R2 extends Type, E2 extends Type, B extends Type>(f: (e: E) => IO<R2, E2, B>): IO<R
|
|
2482
|
+
recoverWith<R2 extends Type, E2 extends Type, B extends Type>(f: (e: E) => IO<R2, E2, B>): IO<R | R2, E2, A | B>;
|
|
2914
2483
|
/**
|
|
2915
2484
|
* Pattern matches on success and failure.
|
|
2916
2485
|
* @param onFailure - Handler for failures
|
|
2917
2486
|
* @param onSuccess - Handler for successes
|
|
2918
2487
|
* @returns New IO with handled result
|
|
2919
2488
|
*/
|
|
2920
|
-
fold<B extends Type>(onFailure: (e: E) => B, onSuccess: (a: A) => B): IO<R
|
|
2489
|
+
fold<B extends Type>(onFailure: (e: E) => B, onSuccess: (a: A) => B): IO<R, never, B>;
|
|
2921
2490
|
/**
|
|
2922
2491
|
* Pattern matches with object pattern syntax.
|
|
2923
2492
|
*/
|
|
2924
2493
|
match<B extends Type>(patterns: {
|
|
2925
2494
|
failure: (e: E) => B;
|
|
2926
2495
|
success: (a: A) => B;
|
|
2927
|
-
}): IO<R
|
|
2496
|
+
}): IO<R, never, B>;
|
|
2928
2497
|
/**
|
|
2929
2498
|
* Catches errors with a specific tag and handles them.
|
|
2930
2499
|
* @param tag - The error tag to catch
|
|
2931
2500
|
* @param handler - Handler for the caught error
|
|
2932
2501
|
*/
|
|
2933
|
-
catchTag<K
|
|
2502
|
+
catchTag<K extends (E extends {
|
|
2934
2503
|
_tag: string;
|
|
2935
|
-
} ? E["_tag"] : never), R2 extends Type, E2 extends Type, B extends Type>(tag: K
|
|
2936
|
-
_tag: K
|
|
2937
|
-
}>) => IO<R2, E2, B>): IO<R
|
|
2938
|
-
_tag: K
|
|
2504
|
+
} ? E["_tag"] : never), R2 extends Type, E2 extends Type, B extends Type>(tag: K, handler: (e: Extract<E, {
|
|
2505
|
+
_tag: K;
|
|
2506
|
+
}>) => IO<R2, E2, B>): IO<R | R2, Exclude<E, {
|
|
2507
|
+
_tag: K;
|
|
2939
2508
|
}> | E2, A | B>;
|
|
2940
2509
|
/**
|
|
2941
2510
|
* Catches all errors (alias for recoverWith).
|
|
2942
2511
|
*/
|
|
2943
|
-
catchAll<R2 extends Type, E2 extends Type, B extends Type>(handler: (e: E) => IO<R2, E2, B>): IO<R
|
|
2512
|
+
catchAll<R2 extends Type, E2 extends Type, B extends Type>(handler: (e: E) => IO<R2, E2, B>): IO<R | R2, E2, A | B>;
|
|
2944
2513
|
/**
|
|
2945
2514
|
* Retries the effect up to n times on failure.
|
|
2946
2515
|
* @param n - Maximum number of retries
|
|
2947
2516
|
*/
|
|
2948
|
-
retry(n: number): IO<R
|
|
2517
|
+
retry(n: number): IO<R, E, A>;
|
|
2949
2518
|
/**
|
|
2950
2519
|
* Retries the effect with a delay between attempts.
|
|
2951
2520
|
* @param n - Maximum number of retries
|
|
2952
2521
|
* @param delayMs - Delay between retries in milliseconds
|
|
2953
2522
|
*/
|
|
2954
|
-
retryWithDelay(n: number, delayMs: number): IO<R
|
|
2523
|
+
retryWithDelay(n: number, delayMs: number): IO<R, E, A>;
|
|
2955
2524
|
/**
|
|
2956
2525
|
* Sequences two IOs, keeping the second value.
|
|
2957
2526
|
*/
|
|
2958
|
-
zipRight<R2 extends Type, E2 extends Type, B extends Type>(that: IO<R2, E2, B>): IO<R
|
|
2527
|
+
zipRight<R2 extends Type, E2 extends Type, B extends Type>(that: IO<R2, E2, B>): IO<R | R2, E | E2, B>;
|
|
2959
2528
|
/**
|
|
2960
2529
|
* Sequences two IOs, keeping the first value.
|
|
2961
2530
|
*/
|
|
2962
|
-
zipLeft<R2 extends Type, E2 extends Type, B extends Type>(that: IO<R2, E2, B>): IO<R
|
|
2531
|
+
zipLeft<R2 extends Type, E2 extends Type, B extends Type>(that: IO<R2, E2, B>): IO<R | R2, E | E2, A>;
|
|
2963
2532
|
/**
|
|
2964
2533
|
* Zips two IOs into a tuple.
|
|
2965
2534
|
*/
|
|
2966
|
-
zip<R2 extends Type, E2 extends Type, B extends Type>(that: IO<R2, E2, B>): IO<R
|
|
2535
|
+
zip<R2 extends Type, E2 extends Type, B extends Type>(that: IO<R2, E2, B>): IO<R | R2, E | E2, readonly [A, B]>;
|
|
2967
2536
|
/**
|
|
2968
2537
|
* Flattens a nested IO.
|
|
2969
2538
|
*/
|
|
2970
|
-
flatten<R2 extends Type, E2 extends Type, B extends Type>(this: IO<R
|
|
2539
|
+
flatten<R2 extends Type, E2 extends Type, B extends Type>(this: IO<R, E, IO<R2, E2, B>>): IO<R | R2, E | E2, B>;
|
|
2971
2540
|
/**
|
|
2972
2541
|
* Provides a context to satisfy the requirements of this effect.
|
|
2973
2542
|
* @param context - The context containing required services
|
|
2974
2543
|
*/
|
|
2975
|
-
provideContext<R2 extends R
|
|
2544
|
+
provideContext<R2 extends R>(context: Context<R2>): IO<Exclude<R, R2>, E, A>;
|
|
2976
2545
|
/**
|
|
2977
2546
|
* Provides a single service to satisfy part of the requirements.
|
|
2978
2547
|
* @param tag - The service tag
|
|
2979
2548
|
* @param service - The service implementation
|
|
2980
2549
|
*/
|
|
2981
|
-
provideService<S extends Type>(tag: Tag<S>, service: S): IO<Exclude<R
|
|
2550
|
+
provideService<S extends Type>(tag: Tag<S>, service: S): IO<Exclude<R, S>, E, A>;
|
|
2982
2551
|
/**
|
|
2983
2552
|
* Provides services using a layer.
|
|
2984
2553
|
* @param layer - The layer that provides services
|
|
2985
2554
|
*/
|
|
2986
|
-
provideLayer<RIn extends Type, E2 extends Type, ROut extends R
|
|
2555
|
+
provideLayer<RIn extends Type, E2 extends Type, ROut extends R>(layer: Layer<RIn, E2, ROut>): IO<RIn | Exclude<R, ROut>, E | E2, A>;
|
|
2987
2556
|
/**
|
|
2988
2557
|
* Runs the effect and returns an Either. Never throws.
|
|
2989
2558
|
* This is the safe default - all errors become Left.
|
|
@@ -3026,22 +2595,22 @@ interface IO<R$1 extends Type, E extends Type, A extends Type> {
|
|
|
3026
2595
|
/**
|
|
3027
2596
|
* Pipes the IO through a function.
|
|
3028
2597
|
*/
|
|
3029
|
-
pipe<B>(f: (self: IO<R
|
|
2598
|
+
pipe<B>(f: (self: IO<R, E, A>) => B): B;
|
|
3030
2599
|
/**
|
|
3031
2600
|
* Delays execution by the specified milliseconds.
|
|
3032
2601
|
*/
|
|
3033
|
-
delay(ms: number): IO<R
|
|
2602
|
+
delay(ms: number): IO<R, E, A>;
|
|
3034
2603
|
/**
|
|
3035
2604
|
* Fails with TimeoutError if the effect doesn't complete within the specified duration.
|
|
3036
2605
|
* @param ms - Maximum time in milliseconds
|
|
3037
2606
|
*/
|
|
3038
|
-
timeout(ms: number): IO<R
|
|
2607
|
+
timeout(ms: number): IO<R, E | TimeoutError, A>;
|
|
3039
2608
|
/**
|
|
3040
2609
|
* Returns a fallback value if the effect doesn't complete within the specified duration.
|
|
3041
2610
|
* @param ms - Maximum time in milliseconds
|
|
3042
2611
|
* @param fallback - Value to return on timeout
|
|
3043
2612
|
*/
|
|
3044
|
-
timeoutTo<B extends Type>(ms: number, fallback: B): IO<R
|
|
2613
|
+
timeoutTo<B extends Type>(ms: number, fallback: B): IO<R, E, A | B>;
|
|
3045
2614
|
/**
|
|
3046
2615
|
* Converts to string representation.
|
|
3047
2616
|
*/
|
|
@@ -3057,52 +2626,52 @@ interface IO<R$1 extends Type, E extends Type, A extends Type> {
|
|
|
3057
2626
|
* Makes IO iterable for generator do-notation (yield* syntax).
|
|
3058
2627
|
* Yields the IO itself, allowing IO.gen to extract the value.
|
|
3059
2628
|
*/
|
|
3060
|
-
[Symbol.iterator](): Generator<IO<R
|
|
2629
|
+
[Symbol.iterator](): Generator<IO<R, E, A>, A, A>;
|
|
3061
2630
|
}
|
|
3062
2631
|
/**
|
|
3063
2632
|
* Do-builder interface for chaining binds and maps
|
|
3064
2633
|
*/
|
|
3065
|
-
interface DoBuilder<R
|
|
2634
|
+
interface DoBuilder<R extends Type, E extends Type, Ctx extends Record<string, Type>> {
|
|
3066
2635
|
/**
|
|
3067
2636
|
* The underlying IO effect
|
|
3068
2637
|
*/
|
|
3069
|
-
readonly effect: IO<R
|
|
2638
|
+
readonly effect: IO<R, E, Ctx>;
|
|
3070
2639
|
/**
|
|
3071
2640
|
* Binds the result of an effect to a named property in the context.
|
|
3072
2641
|
* @param name - The property name to bind to
|
|
3073
2642
|
* @param f - Function that returns an IO effect (receives current context)
|
|
3074
2643
|
*/
|
|
3075
|
-
bind<N extends string, R2 extends Type, E2 extends Type, A extends Type>(name: Exclude<N, keyof Ctx>, f: (ctx: Ctx) => IO<R2, E2, A>): DoBuilder<R
|
|
2644
|
+
bind<N extends string, R2 extends Type, E2 extends Type, A extends Type>(name: Exclude<N, keyof Ctx>, f: (ctx: Ctx) => IO<R2, E2, A>): DoBuilder<R | R2, E | E2, Ctx & Record<N, A>>;
|
|
3076
2645
|
/**
|
|
3077
2646
|
* Binds a pure value to a named property in the context.
|
|
3078
2647
|
* @param name - The property name to bind to
|
|
3079
2648
|
* @param f - Function that returns a value (receives current context)
|
|
3080
2649
|
*/
|
|
3081
|
-
let<N extends string, A extends Type>(name: Exclude<N, keyof Ctx>, f: (ctx: Ctx) => A): DoBuilder<R
|
|
2650
|
+
let<N extends string, A extends Type>(name: Exclude<N, keyof Ctx>, f: (ctx: Ctx) => A): DoBuilder<R, E, Ctx & Record<N, A>>;
|
|
3082
2651
|
/**
|
|
3083
2652
|
* Transforms the final context value.
|
|
3084
2653
|
* @param f - Function to transform the context
|
|
3085
2654
|
*/
|
|
3086
|
-
map<B extends Type>(f: (ctx: Ctx) => B): IO<R
|
|
2655
|
+
map<B extends Type>(f: (ctx: Ctx) => B): IO<R, E, B>;
|
|
3087
2656
|
/**
|
|
3088
2657
|
* Chains to another IO based on the context.
|
|
3089
2658
|
* @param f - Function that returns an IO effect
|
|
3090
2659
|
*/
|
|
3091
|
-
flatMap<R2 extends Type, E2 extends Type, B extends Type>(f: (ctx: Ctx) => IO<R2, E2, B>): IO<R
|
|
2660
|
+
flatMap<R2 extends Type, E2 extends Type, B extends Type>(f: (ctx: Ctx) => IO<R2, E2, B>): IO<R | R2, E | E2, B>;
|
|
3092
2661
|
/**
|
|
3093
2662
|
* Executes a side effect without changing the context.
|
|
3094
2663
|
* @param f - Side effect function
|
|
3095
2664
|
*/
|
|
3096
|
-
tap(f: (ctx: Ctx) => void): DoBuilder<R
|
|
2665
|
+
tap(f: (ctx: Ctx) => void): DoBuilder<R, E, Ctx>;
|
|
3097
2666
|
/**
|
|
3098
2667
|
* Executes an effectful side effect without changing the context.
|
|
3099
2668
|
* @param f - Function returning an IO for the side effect
|
|
3100
2669
|
*/
|
|
3101
|
-
tapEffect<R2 extends Type, E2 extends Type, B extends Type>(f: (ctx: Ctx) => IO<R2, E2, B>): DoBuilder<R
|
|
2670
|
+
tapEffect<R2 extends Type, E2 extends Type, B extends Type>(f: (ctx: Ctx) => IO<R2, E2, B>): DoBuilder<R | R2, E | E2, Ctx>;
|
|
3102
2671
|
/**
|
|
3103
2672
|
* Returns the final context as is.
|
|
3104
2673
|
*/
|
|
3105
|
-
done(): IO<R
|
|
2674
|
+
done(): IO<R, E, Ctx>;
|
|
3106
2675
|
}
|
|
3107
2676
|
/**
|
|
3108
2677
|
* IO effect type for lazy, composable effects with typed errors.
|
|
@@ -3315,7 +2884,7 @@ declare const IO: (<A extends Type>(f: () => A | Promise<A>) => IO<never, unknow
|
|
|
3315
2884
|
/**
|
|
3316
2885
|
* Accesses a service and applies an effectful function to it.
|
|
3317
2886
|
*/
|
|
3318
|
-
serviceWithIO: <S extends Type, R
|
|
2887
|
+
serviceWithIO: <S extends Type, R extends Type, E extends Type, A extends Type>(tag: Tag<S>, f: (service: S) => IO<R, E, A>) => IO<S | R, E, A>;
|
|
3319
2888
|
/**
|
|
3320
2889
|
* Accesses multiple services and applies a function to them.
|
|
3321
2890
|
* Provides a convenient way to work with multiple dependencies.
|
|
@@ -3335,11 +2904,11 @@ declare const IO: (<A extends Type>(f: () => A | Promise<A>) => IO<never, unknow
|
|
|
3335
2904
|
/**
|
|
3336
2905
|
* Runs all IOs in parallel and collects results.
|
|
3337
2906
|
*/
|
|
3338
|
-
all: <R
|
|
2907
|
+
all: <R extends Type, E extends Type, A extends Type>(effects: readonly IO<R, E, A>[]) => IO<R, E, readonly A[]>;
|
|
3339
2908
|
/**
|
|
3340
2909
|
* Runs IOs in sequence, returning the first success or last failure.
|
|
3341
2910
|
*/
|
|
3342
|
-
firstSuccessOf: <R
|
|
2911
|
+
firstSuccessOf: <R extends Type, E extends Type, A extends Type>(effects: readonly IO<R, E, A>[]) => IO<R, E, A>;
|
|
3343
2912
|
/**
|
|
3344
2913
|
* Creates an IO that sleeps for the specified duration.
|
|
3345
2914
|
*/
|
|
@@ -3373,11 +2942,11 @@ declare const IO: (<A extends Type>(f: () => A | Promise<A>) => IO<never, unknow
|
|
|
3373
2942
|
* )
|
|
3374
2943
|
* ```
|
|
3375
2944
|
*/
|
|
3376
|
-
bracket: <R
|
|
2945
|
+
bracket: <R extends Type, E extends Type, A extends Type, B extends Type>(acquire: IO<R, E, A>, use: (a: A) => IO<R, E, B>, release: (a: A) => IO<R, never, void>) => IO<R, E, B>;
|
|
3377
2946
|
/**
|
|
3378
2947
|
* Alias for bracket with a more descriptive name.
|
|
3379
2948
|
*/
|
|
3380
|
-
acquireRelease: <R
|
|
2949
|
+
acquireRelease: <R extends Type, E extends Type, A extends Type, B extends Type>(acquire: IO<R, E, A>, use: (a: A) => IO<R, E, B>, release: (a: A) => IO<R, never, void>) => IO<R, E, B>;
|
|
3381
2950
|
/**
|
|
3382
2951
|
* Races multiple effects, returning the first to complete.
|
|
3383
2952
|
* Note: Other effects are NOT cancelled (JS limitation).
|
|
@@ -3390,7 +2959,7 @@ declare const IO: (<A extends Type>(f: () => A | Promise<A>) => IO<never, unknow
|
|
|
3390
2959
|
* ]).run() // "fast"
|
|
3391
2960
|
* ```
|
|
3392
2961
|
*/
|
|
3393
|
-
race: <R
|
|
2962
|
+
race: <R extends Type, E extends Type, A extends Type>(effects: readonly IO<R, E, A>[]) => IO<R, E, A>;
|
|
3394
2963
|
/**
|
|
3395
2964
|
* Returns the first effect to succeed, or fails if all fail.
|
|
3396
2965
|
*
|
|
@@ -3403,7 +2972,7 @@ declare const IO: (<A extends Type>(f: () => A | Promise<A>) => IO<never, unknow
|
|
|
3403
2972
|
* ]).run() // "success"
|
|
3404
2973
|
* ```
|
|
3405
2974
|
*/
|
|
3406
|
-
any: <R
|
|
2975
|
+
any: <R extends Type, E extends Type, A extends Type>(effects: readonly IO<R, E, A>[]) => IO<R, E, A>;
|
|
3407
2976
|
/**
|
|
3408
2977
|
* Executes an effect for each element in the array, collecting results.
|
|
3409
2978
|
*
|
|
@@ -3414,16 +2983,16 @@ declare const IO: (<A extends Type>(f: () => A | Promise<A>) => IO<never, unknow
|
|
|
3414
2983
|
* ).run() // [2, 4, 6]
|
|
3415
2984
|
* ```
|
|
3416
2985
|
*/
|
|
3417
|
-
forEach: <R
|
|
2986
|
+
forEach: <R extends Type, E extends Type, A extends Type, B extends Type>(items: readonly A[], f: (a: A) => IO<R, E, B>) => IO<R, E, readonly B[]>;
|
|
3418
2987
|
/**
|
|
3419
2988
|
* Executes effects for each element in parallel (limited concurrency coming later).
|
|
3420
2989
|
* Alias for forEach.
|
|
3421
2990
|
*/
|
|
3422
|
-
forEachPar: <R
|
|
2991
|
+
forEachPar: <R extends Type, E extends Type, A extends Type, B extends Type>(items: readonly A[], f: (a: A) => IO<R, E, B>) => IO<R, E, readonly B[]>;
|
|
3423
2992
|
/**
|
|
3424
2993
|
* Creates a timeout effect that fails with TimeoutError.
|
|
3425
2994
|
*/
|
|
3426
|
-
timeout: <R
|
|
2995
|
+
timeout: <R extends Type, E extends Type, A extends Type>(effect: IO<R, E, A>, ms: number) => IO<R, E | TimeoutError, A>;
|
|
3427
2996
|
/**
|
|
3428
2997
|
* Creates an IO from a generator function.
|
|
3429
2998
|
* This enables do-notation style programming.
|
|
@@ -3464,7 +3033,7 @@ type Task<E extends Type, A extends Type> = IO<never, E, A>;
|
|
|
3464
3033
|
/**
|
|
3465
3034
|
* An IO with no error
|
|
3466
3035
|
*/
|
|
3467
|
-
type RIO<R
|
|
3036
|
+
type RIO<R extends Type, A extends Type> = IO<R, never, A>;
|
|
3468
3037
|
//#endregion
|
|
3469
3038
|
//#region src/io/TestClock.d.ts
|
|
3470
3039
|
/**
|
|
@@ -3556,11 +3125,11 @@ declare const TestClock: {
|
|
|
3556
3125
|
/**
|
|
3557
3126
|
* TestContext provides a complete test environment with mocked services.
|
|
3558
3127
|
*/
|
|
3559
|
-
interface TestContext<R
|
|
3128
|
+
interface TestContext<R extends Type> {
|
|
3560
3129
|
/**
|
|
3561
3130
|
* The context containing test services
|
|
3562
3131
|
*/
|
|
3563
|
-
readonly context: ReturnType<typeof Context.empty<R
|
|
3132
|
+
readonly context: ReturnType<typeof Context.empty<R>>;
|
|
3564
3133
|
/**
|
|
3565
3134
|
* The TestClock for controlling time
|
|
3566
3135
|
*/
|
|
@@ -3568,11 +3137,11 @@ interface TestContext<R$1 extends Type> {
|
|
|
3568
3137
|
/**
|
|
3569
3138
|
* Adds a service to the test context
|
|
3570
3139
|
*/
|
|
3571
|
-
withService<S extends Type>(tag: Tag<S>, service: S): TestContext<R
|
|
3140
|
+
withService<S extends Type>(tag: Tag<S>, service: S): TestContext<R & S>;
|
|
3572
3141
|
/**
|
|
3573
3142
|
* Provides the test context to an IO effect and runs it
|
|
3574
3143
|
*/
|
|
3575
|
-
run<E extends Type, A extends Type>(effect: IO<R
|
|
3144
|
+
run<E extends Type, A extends Type>(effect: IO<R, E, A>): Promise<A>;
|
|
3576
3145
|
}
|
|
3577
3146
|
/**
|
|
3578
3147
|
* Creates a TestContext for testing IO effects with mocked services.
|
|
@@ -3590,7 +3159,7 @@ declare const TestContext: {
|
|
|
3590
3159
|
/**
|
|
3591
3160
|
* Creates a new empty TestContext
|
|
3592
3161
|
*/
|
|
3593
|
-
make: <R
|
|
3162
|
+
make: <R extends Type = never>() => TestContext<R>;
|
|
3594
3163
|
/**
|
|
3595
3164
|
* Creates a TestContext with a TestClock already provided
|
|
3596
3165
|
*/
|
|
@@ -3748,9 +3317,9 @@ interface Lazy<T extends Type> extends FunctypeBase<T, "Lazy">, Extractable<T>,
|
|
|
3748
3317
|
* @param patterns - Object with handler for Lazy pattern
|
|
3749
3318
|
* @returns The result of the matched handler
|
|
3750
3319
|
*/
|
|
3751
|
-
match<R
|
|
3752
|
-
Lazy: (value: T) => R
|
|
3753
|
-
}): R
|
|
3320
|
+
match<R>(patterns: {
|
|
3321
|
+
Lazy: (value: T) => R;
|
|
3322
|
+
}): R;
|
|
3754
3323
|
/**
|
|
3755
3324
|
* Creates a string representation of the Lazy
|
|
3756
3325
|
* @returns String representation showing evaluation status
|
|
@@ -3863,60 +3432,6 @@ interface Traversable<A extends Type> extends AsyncMonad<A> {
|
|
|
3863
3432
|
reduceRight(f: (b: A, a: A) => A): A;
|
|
3864
3433
|
}
|
|
3865
3434
|
//#endregion
|
|
3866
|
-
//#region src/map/Map.d.ts
|
|
3867
|
-
/**
|
|
3868
|
-
* A traversable interface for map that excludes map and flatMap operations
|
|
3869
|
-
*/
|
|
3870
|
-
type SafeTraversable<K$1, V> = Omit<Traversable<Tuple<[K$1, V]>>, "map" | "flatMap" | "flatMapAsync" | "ap">;
|
|
3871
|
-
interface Map$1<K$1, V> extends SafeTraversable<K$1, V>, Collection<Tuple<[K$1, V]>>, Typeable<"Map">, Serializable<[K$1, V][]>, Pipe<[K$1, V][]>, Foldable<Tuple<[K$1, V]>>, Iterable<[K$1, V]> {
|
|
3872
|
-
readonly _tag: "Map";
|
|
3873
|
-
add(item: Tuple<[K$1, V]>): Map$1<K$1, V>;
|
|
3874
|
-
remove(value: K$1): Map$1<K$1, V>;
|
|
3875
|
-
map<U>(f: (value: V) => U): Map$1<K$1, U>;
|
|
3876
|
-
ap<U>(ff: Map$1<K$1, (value: V) => U>): Map$1<K$1, U>;
|
|
3877
|
-
flatMap<K2, V2>(f: (entry: Tuple<[K$1, V]>) => Iterable<[K2, V2]>): Map$1<K2, V2>;
|
|
3878
|
-
flatMapAsync<U>(f: (value: V) => PromiseLike<Map$1<K$1, U>>): PromiseLike<Map$1<K$1, U>>;
|
|
3879
|
-
get(key: K$1): Option<V>;
|
|
3880
|
-
getOrElse(key: K$1, defaultValue: V): V;
|
|
3881
|
-
orElse(key: K$1, alternative: Option<V>): Option<V>;
|
|
3882
|
-
fold<U extends Type>(onEmpty: () => U, onValue: (value: Tuple<[K$1, V]>) => U): U;
|
|
3883
|
-
foldLeft<B>(z: B): (op: (b: B, a: Tuple<[K$1, V]>) => B) => B;
|
|
3884
|
-
foldRight<B>(z: B): (op: (a: Tuple<[K$1, V]>, b: B) => B) => B;
|
|
3885
|
-
/**
|
|
3886
|
-
* Pattern matches over the Map, applying a handler function based on whether it's empty
|
|
3887
|
-
* @param patterns - Object with handler functions for Empty and NonEmpty variants
|
|
3888
|
-
* @returns The result of applying the matching handler function
|
|
3889
|
-
*/
|
|
3890
|
-
match<R$1>(patterns: {
|
|
3891
|
-
Empty: () => R$1;
|
|
3892
|
-
NonEmpty: (entries: Array<Tuple<[K$1, V]>>) => R$1;
|
|
3893
|
-
}): R$1;
|
|
3894
|
-
toValue(): {
|
|
3895
|
-
_tag: "Map";
|
|
3896
|
-
value: [K$1, V][];
|
|
3897
|
-
};
|
|
3898
|
-
}
|
|
3899
|
-
declare const Map$1: (<K$1, V>(entries?: readonly (readonly [K$1, V])[] | IterableIterator<[K$1, V]> | null) => Map$1<K$1, V>) & {
|
|
3900
|
-
/**
|
|
3901
|
-
* Creates a Map from JSON string
|
|
3902
|
-
* @param json - The JSON string
|
|
3903
|
-
* @returns Map instance
|
|
3904
|
-
*/
|
|
3905
|
-
fromJSON: <K$1, V>(json: string) => Map$1<K$1, V>;
|
|
3906
|
-
/**
|
|
3907
|
-
* Creates a Map from YAML string
|
|
3908
|
-
* @param yaml - The YAML string
|
|
3909
|
-
* @returns Map instance
|
|
3910
|
-
*/
|
|
3911
|
-
fromYAML: <K$1, V>(yaml: string) => Map$1<K$1, V>;
|
|
3912
|
-
/**
|
|
3913
|
-
* Creates a Map from binary string
|
|
3914
|
-
* @param binary - The binary string
|
|
3915
|
-
* @returns Map instance
|
|
3916
|
-
*/
|
|
3917
|
-
fromBinary: <K$1, V>(binary: string) => Map$1<K$1, V>;
|
|
3918
|
-
};
|
|
3919
|
-
//#endregion
|
|
3920
3435
|
//#region src/map/shim.d.ts
|
|
3921
3436
|
/**
|
|
3922
3437
|
* Type alias for the native JavaScript Map
|
|
@@ -3924,7 +3439,7 @@ declare const Map$1: (<K$1, V>(entries?: readonly (readonly [K$1, V])[] | Iterab
|
|
|
3924
3439
|
* @module Map
|
|
3925
3440
|
* @category Collections
|
|
3926
3441
|
*/
|
|
3927
|
-
type ESMapType<K
|
|
3442
|
+
type ESMapType<K, V> = Map<K, V>;
|
|
3928
3443
|
/**
|
|
3929
3444
|
* Reference to the native JavaScript Map
|
|
3930
3445
|
* @module Map
|
|
@@ -3949,7 +3464,7 @@ interface Matchable<A, Tags extends string = string> {
|
|
|
3949
3464
|
* @param patterns - An object containing handler functions for each variant
|
|
3950
3465
|
* @returns The result of applying the matching handler function
|
|
3951
3466
|
*/
|
|
3952
|
-
match<R
|
|
3467
|
+
match<R>(patterns: Record<Tags, (value: A) => R>): R;
|
|
3953
3468
|
}
|
|
3954
3469
|
/**
|
|
3955
3470
|
* Utility functions for working with Matchable data structures
|
|
@@ -3961,7 +3476,7 @@ declare const MatchableUtils: {
|
|
|
3961
3476
|
* @param handler - The default handler function to apply
|
|
3962
3477
|
* @returns A function that always applies the default handler
|
|
3963
3478
|
*/
|
|
3964
|
-
default: <A, R
|
|
3479
|
+
default: <A, R>(handler: (value: A) => R) => (value: A) => R;
|
|
3965
3480
|
/**
|
|
3966
3481
|
* Helper function to create a match pattern that guards based on a predicate
|
|
3967
3482
|
*
|
|
@@ -3969,7 +3484,7 @@ declare const MatchableUtils: {
|
|
|
3969
3484
|
* @param handler - The handler function to apply if the predicate passes
|
|
3970
3485
|
* @returns A function that applies the handler only if the predicate passes
|
|
3971
3486
|
*/
|
|
3972
|
-
when: <A, R
|
|
3487
|
+
when: <A, R>(predicate: (value: A) => boolean, handler: (value: A) => R) => (value: A) => R | undefined;
|
|
3973
3488
|
};
|
|
3974
3489
|
//#endregion
|
|
3975
3490
|
//#region src/ref/Ref.d.ts
|
|
@@ -4097,49 +3612,12 @@ declare const createSerializationCompanion: <T>(reconstructor: (parsed: {
|
|
|
4097
3612
|
fromBinary: (binary: string) => T;
|
|
4098
3613
|
};
|
|
4099
3614
|
//#endregion
|
|
4100
|
-
//#region src/set/Set.d.ts
|
|
4101
|
-
interface Set<A> extends FunctypeCollection<A, "Set">, Collection<A> {
|
|
4102
|
-
add: (value: A) => Set<A>;
|
|
4103
|
-
remove: (value: A) => Set<A>;
|
|
4104
|
-
contains: (value: A) => boolean;
|
|
4105
|
-
has: (value: A) => boolean;
|
|
4106
|
-
map: <B>(f: (a: A) => B) => Set<B>;
|
|
4107
|
-
flatMap: <B>(f: (a: A) => Iterable<B>) => Set<B>;
|
|
4108
|
-
filter: (p: (a: A) => boolean) => Set<A>;
|
|
4109
|
-
filterNot: (p: (a: A) => boolean) => Set<A>;
|
|
4110
|
-
fold: <U extends Type>(onEmpty: () => U, onValue: (value: A) => U) => U;
|
|
4111
|
-
toList: () => List<A>;
|
|
4112
|
-
toSet: () => Set<A>;
|
|
4113
|
-
toArray: <B = A>() => B[];
|
|
4114
|
-
toString: () => string;
|
|
4115
|
-
}
|
|
4116
|
-
declare const Set: (<A>(iterable?: Iterable<A>) => Set<A>) & {
|
|
4117
|
-
/**
|
|
4118
|
-
* Creates a Set from JSON string
|
|
4119
|
-
* @param json - The JSON string
|
|
4120
|
-
* @returns Set instance
|
|
4121
|
-
*/
|
|
4122
|
-
fromJSON: <A>(json: string) => Set<A>;
|
|
4123
|
-
/**
|
|
4124
|
-
* Creates a Set from YAML string
|
|
4125
|
-
* @param yaml - The YAML string
|
|
4126
|
-
* @returns Set instance
|
|
4127
|
-
*/
|
|
4128
|
-
fromYAML: <A>(yaml: string) => Set<A>;
|
|
4129
|
-
/**
|
|
4130
|
-
* Creates a Set from binary string
|
|
4131
|
-
* @param binary - The binary string
|
|
4132
|
-
* @returns Set instance
|
|
4133
|
-
*/
|
|
4134
|
-
fromBinary: <A>(binary: string) => Set<A>;
|
|
4135
|
-
};
|
|
4136
|
-
//#endregion
|
|
4137
3615
|
//#region src/valuable/Valuable.d.ts
|
|
4138
3616
|
/**
|
|
4139
3617
|
* Parameters for creating a Valuable instance
|
|
4140
3618
|
*/
|
|
4141
|
-
type ValuableParams<Tag
|
|
4142
|
-
_tag: Tag
|
|
3619
|
+
type ValuableParams<Tag extends string, T, V> = {
|
|
3620
|
+
_tag: Tag;
|
|
4143
3621
|
impl: T;
|
|
4144
3622
|
value: V;
|
|
4145
3623
|
};
|
|
@@ -4149,16 +3627,16 @@ type ValuableParams<Tag$1 extends string, T, V> = {
|
|
|
4149
3627
|
* @module Valuable
|
|
4150
3628
|
* @category Utilities
|
|
4151
3629
|
*/
|
|
4152
|
-
declare function Valuable<Tag
|
|
3630
|
+
declare function Valuable<Tag extends string, V, T = object>(params: ValuableParams<Tag, T, V>): T & {
|
|
4153
3631
|
toValue: () => {
|
|
4154
|
-
_tag: Tag
|
|
3632
|
+
_tag: Tag;
|
|
4155
3633
|
value: V;
|
|
4156
3634
|
};
|
|
4157
|
-
_tag: Tag
|
|
3635
|
+
_tag: Tag;
|
|
4158
3636
|
};
|
|
4159
|
-
type Valuable<Tag
|
|
3637
|
+
type Valuable<Tag extends string, V, T = object> = Typeable<Tag, T> & {
|
|
4160
3638
|
toValue: () => {
|
|
4161
|
-
_tag: Tag
|
|
3639
|
+
_tag: Tag;
|
|
4162
3640
|
value: V;
|
|
4163
3641
|
};
|
|
4164
3642
|
};
|
|
@@ -4229,10 +3707,10 @@ type Stack<A extends Type> = {
|
|
|
4229
3707
|
* @param patterns - Object with handler functions for Empty and NonEmpty variants
|
|
4230
3708
|
* @returns The result of applying the matching handler function
|
|
4231
3709
|
*/
|
|
4232
|
-
match<R
|
|
4233
|
-
Empty: () => R
|
|
4234
|
-
NonEmpty: (values: A[]) => R
|
|
4235
|
-
}): R
|
|
3710
|
+
match<R>(patterns: {
|
|
3711
|
+
Empty: () => R;
|
|
3712
|
+
NonEmpty: (values: A[]) => R;
|
|
3713
|
+
}): R;
|
|
4236
3714
|
} & Traversable<A> & Valuable<"Stack", A[]> & Serializable<A> & Pipe<A[]> & Foldable<A> & Matchable<A[], "Empty" | "NonEmpty">;
|
|
4237
3715
|
declare const Stack: (<A extends Type>(values?: A[]) => Stack<A>) & {
|
|
4238
3716
|
/**
|
|
@@ -4266,292 +3744,6 @@ declare const Stack: (<A extends Type>(values?: A[]) => Stack<A>) & {
|
|
|
4266
3744
|
fromBinary: <A>(binary: string) => Stack<A>;
|
|
4267
3745
|
};
|
|
4268
3746
|
//#endregion
|
|
4269
|
-
//#region src/option/Option.d.ts
|
|
4270
|
-
/**
|
|
4271
|
-
* Option type module
|
|
4272
|
-
* @module Option
|
|
4273
|
-
* @category Core
|
|
4274
|
-
*/
|
|
4275
|
-
/**
|
|
4276
|
-
* The Option type represents a value that may or may not exist.
|
|
4277
|
-
* It's used to handle potentially null or undefined values in a type-safe way.
|
|
4278
|
-
* @typeParam T - The type of the value contained in the Option
|
|
4279
|
-
*/
|
|
4280
|
-
interface Option<T extends Type> extends Functype<T, "Some" | "None">, Promisable<T>, Doable<T>, Reshapeable<T> {
|
|
4281
|
-
/** The contained value (undefined for None) */
|
|
4282
|
-
readonly value: T | undefined;
|
|
4283
|
-
/** Whether this Option contains no value */
|
|
4284
|
-
isEmpty: boolean;
|
|
4285
|
-
/**
|
|
4286
|
-
* Returns true if this Option is a Some (contains a value)
|
|
4287
|
-
* @returns true if this Option contains a value, false otherwise
|
|
4288
|
-
*/
|
|
4289
|
-
isSome(): this is Option<T> & {
|
|
4290
|
-
value: T;
|
|
4291
|
-
isEmpty: false;
|
|
4292
|
-
};
|
|
4293
|
-
/**
|
|
4294
|
-
* Returns true if this Option is a None (contains no value)
|
|
4295
|
-
* @returns true if this Option is empty, false otherwise
|
|
4296
|
-
*/
|
|
4297
|
-
isNone(): this is Option<T> & {
|
|
4298
|
-
value: undefined;
|
|
4299
|
-
isEmpty: true;
|
|
4300
|
-
};
|
|
4301
|
-
/**
|
|
4302
|
-
* Returns the contained value or a default value if None
|
|
4303
|
-
* @param defaultValue - The value to return if this Option is None
|
|
4304
|
-
* @returns The contained value or defaultValue
|
|
4305
|
-
*/
|
|
4306
|
-
orElse(defaultValue: T): T;
|
|
4307
|
-
/**
|
|
4308
|
-
* Returns the contained value or throws an error if None
|
|
4309
|
-
* @param error - Optional custom error to throw. If not provided, throws a default error
|
|
4310
|
-
* @returns The contained value
|
|
4311
|
-
* @throws The specified error or a default error if the Option is None
|
|
4312
|
-
*/
|
|
4313
|
-
orThrow(error?: Error): T;
|
|
4314
|
-
/**
|
|
4315
|
-
* Returns this Option if it contains a value, otherwise returns the alternative container
|
|
4316
|
-
* @param alternative - The alternative Option to return if this is None
|
|
4317
|
-
* @returns This Option or the alternative
|
|
4318
|
-
*/
|
|
4319
|
-
or(alternative: Option<T>): Option<T>;
|
|
4320
|
-
/**
|
|
4321
|
-
* Returns the contained value or null if None
|
|
4322
|
-
* @returns The contained value or null
|
|
4323
|
-
*/
|
|
4324
|
-
orNull(): T | null;
|
|
4325
|
-
/**
|
|
4326
|
-
* Returns the contained value or undefined if None
|
|
4327
|
-
* @returns The contained value or undefined
|
|
4328
|
-
*/
|
|
4329
|
-
orUndefined(): T | undefined;
|
|
4330
|
-
/**
|
|
4331
|
-
* Maps the value inside the Option using the provided function
|
|
4332
|
-
* @param f - The mapping function
|
|
4333
|
-
* @returns A new Option containing the mapped value, or None if this Option is None
|
|
4334
|
-
*/
|
|
4335
|
-
map<U extends Type>(f: (value: T) => U): Option<U>;
|
|
4336
|
-
/**
|
|
4337
|
-
* Applies a wrapped function to a wrapped value (Applicative pattern)
|
|
4338
|
-
* @param ff - An Option containing a function from T to U
|
|
4339
|
-
* @returns A new Option containing the result of applying the function
|
|
4340
|
-
*/
|
|
4341
|
-
ap<U extends Type>(ff: Option<(value: T) => U>): Option<U>;
|
|
4342
|
-
/**
|
|
4343
|
-
* Returns this Option if it contains a value that satisfies the predicate, otherwise returns None
|
|
4344
|
-
* @param predicate - The predicate function to test the value
|
|
4345
|
-
* @returns This Option or None
|
|
4346
|
-
*/
|
|
4347
|
-
filter(predicate: (value: T) => boolean): Option<T>;
|
|
4348
|
-
/**
|
|
4349
|
-
* Maps the value using a function that returns an Option
|
|
4350
|
-
* @param f - The mapping function returning an Option
|
|
4351
|
-
* @returns The result of applying f to the contained value, or None if this Option is None
|
|
4352
|
-
*/
|
|
4353
|
-
flatMap<U extends Type>(f: (value: T) => Option<U>): Option<U>;
|
|
4354
|
-
/**
|
|
4355
|
-
* Maps the value using an async function that returns an Option
|
|
4356
|
-
* @param f - The async mapping function returning an Option
|
|
4357
|
-
* @returns Promise of the result of applying f to the contained value, or None if this Option is None
|
|
4358
|
-
*/
|
|
4359
|
-
flatMapAsync<U extends Type>(f: (value: T) => Promise<Option<U>>): Promise<Option<U>>;
|
|
4360
|
-
/**
|
|
4361
|
-
* Applies a binary operator to a start value and the contained value
|
|
4362
|
-
* @param f - The binary operator
|
|
4363
|
-
* @returns The result of the reduction
|
|
4364
|
-
*/
|
|
4365
|
-
reduce<U>(f: (acc: U, value: T) => U): U;
|
|
4366
|
-
/**
|
|
4367
|
-
* Applies a binary operator to the contained value and a start value
|
|
4368
|
-
* @param f - The binary operator
|
|
4369
|
-
* @returns The result of the reduction
|
|
4370
|
-
*/
|
|
4371
|
-
reduceRight<U>(f: (acc: U, value: T) => U): U;
|
|
4372
|
-
/**
|
|
4373
|
-
* Pattern matches over the Option, applying onNone if None and onSome if Some
|
|
4374
|
-
* @param onNone - Function to apply if the Option is None
|
|
4375
|
-
* @param onSome - Function to apply if the Option has a value
|
|
4376
|
-
* @returns The result of applying the appropriate function
|
|
4377
|
-
*/
|
|
4378
|
-
fold<U>(onNone: () => U, onSome: (value: T) => U): U;
|
|
4379
|
-
/**
|
|
4380
|
-
* Left-associative fold using the provided zero value and operation
|
|
4381
|
-
* @param z - Zero/identity value
|
|
4382
|
-
* @returns A function that takes an operation to apply
|
|
4383
|
-
*/
|
|
4384
|
-
foldLeft<B>(z: B): (op: (b: B, a: T) => B) => B;
|
|
4385
|
-
/**
|
|
4386
|
-
* Right-associative fold using the provided zero value and operation
|
|
4387
|
-
* @param z - Zero/identity value
|
|
4388
|
-
* @returns A function that takes an operation to apply
|
|
4389
|
-
*/
|
|
4390
|
-
foldRight<B>(z: B): (op: (a: T, b: B) => B) => B;
|
|
4391
|
-
/**
|
|
4392
|
-
* Converts this Option to a List
|
|
4393
|
-
* @returns A List containing the value if Some, or empty List if None
|
|
4394
|
-
*/
|
|
4395
|
-
toList(): List<T>;
|
|
4396
|
-
/**
|
|
4397
|
-
* Checks if this Option contains the specified value
|
|
4398
|
-
* @param value - The value to check for
|
|
4399
|
-
* @returns true if this Option contains the value, false otherwise
|
|
4400
|
-
*/
|
|
4401
|
-
contains(value: T): boolean;
|
|
4402
|
-
/** The number of elements in this Option (0 or 1) */
|
|
4403
|
-
size: number;
|
|
4404
|
-
/**
|
|
4405
|
-
* Converts this Option to an Either
|
|
4406
|
-
* @param left - The value to use for Left if this Option is None
|
|
4407
|
-
* @returns Either.Right with the contained value if Some, or Either.Left with left if None
|
|
4408
|
-
*/
|
|
4409
|
-
toEither<E>(left: E): Either<E, T>;
|
|
4410
|
-
/**
|
|
4411
|
-
* Returns a string representation of this Option
|
|
4412
|
-
* @returns A string representation
|
|
4413
|
-
*/
|
|
4414
|
-
toString(): string;
|
|
4415
|
-
/**
|
|
4416
|
-
* Returns a simple object representation of this Option
|
|
4417
|
-
* @returns An object with _tag and value properties
|
|
4418
|
-
*/
|
|
4419
|
-
toValue(): {
|
|
4420
|
-
_tag: "Some" | "None";
|
|
4421
|
-
value: T;
|
|
4422
|
-
};
|
|
4423
|
-
/**
|
|
4424
|
-
* Pattern matches over the Option, applying a handler function based on the variant
|
|
4425
|
-
* @param patterns - Object with handler functions for Some and None variants
|
|
4426
|
-
* @returns The result of applying the matching handler function
|
|
4427
|
-
*/
|
|
4428
|
-
match<R$1>(patterns: {
|
|
4429
|
-
Some: (value: T) => R$1;
|
|
4430
|
-
None: () => R$1;
|
|
4431
|
-
}): R$1;
|
|
4432
|
-
}
|
|
4433
|
-
/**
|
|
4434
|
-
* Creates a Some variant of Option containing a value.
|
|
4435
|
-
* @param value - The value to wrap in Some
|
|
4436
|
-
* @returns A new Some instance containing the value
|
|
4437
|
-
* @typeParam T - The type of the value
|
|
4438
|
-
*/
|
|
4439
|
-
declare const Some: <T extends Type>(value: T) => Option<T>;
|
|
4440
|
-
/**
|
|
4441
|
-
* Creates a None variant of Option representing absence of a value.
|
|
4442
|
-
* @returns A new None instance
|
|
4443
|
-
* @typeParam T - The type that would be contained if this was a Some
|
|
4444
|
-
*/
|
|
4445
|
-
declare const None: <T extends Type>() => Option<T>;
|
|
4446
|
-
/**
|
|
4447
|
-
* Safely wraps a value that might be null or undefined in an Option.
|
|
4448
|
-
* Creates Some if the value is defined, None otherwise.
|
|
4449
|
-
* @param value - The value to wrap (might be null/undefined)
|
|
4450
|
-
* @returns Some(value) if value is defined, None otherwise
|
|
4451
|
-
* @typeParam T - The type of the value
|
|
4452
|
-
*/
|
|
4453
|
-
declare const OptionConstructor: <T extends Type>(value: T | null | undefined) => Option<T>;
|
|
4454
|
-
declare const Option: (<T extends Type>(value: T | null | undefined) => Option<T>) & {
|
|
4455
|
-
/**
|
|
4456
|
-
* Creates an Option from any value. Alias for Option function.
|
|
4457
|
-
* @param value - The value to wrap
|
|
4458
|
-
* @returns Some(value) if value is defined, None otherwise
|
|
4459
|
-
* @typeParam T - The type of the value
|
|
4460
|
-
*/
|
|
4461
|
-
from: <T>(value: T) => Option<T>;
|
|
4462
|
-
/**
|
|
4463
|
-
* Returns a None instance. Alias for None function.
|
|
4464
|
-
* @returns A None instance
|
|
4465
|
-
* @typeParam T - The type that would be contained if this was a Some
|
|
4466
|
-
*/
|
|
4467
|
-
none: <T>() => Option<T>;
|
|
4468
|
-
/**
|
|
4469
|
-
* Type guard to check if an Option is Some
|
|
4470
|
-
* @param option - The Option to check
|
|
4471
|
-
* @returns True if Option is Some
|
|
4472
|
-
*/
|
|
4473
|
-
isSome: <T>(option: Option<T>) => option is Option<T> & {
|
|
4474
|
-
value: T;
|
|
4475
|
-
isEmpty: false;
|
|
4476
|
-
};
|
|
4477
|
-
/**
|
|
4478
|
-
* Type guard to check if an Option is None
|
|
4479
|
-
* @param option - The Option to check
|
|
4480
|
-
* @returns True if Option is None
|
|
4481
|
-
*/
|
|
4482
|
-
isNone: <T>(option: Option<T>) => option is Option<T> & {
|
|
4483
|
-
value: undefined;
|
|
4484
|
-
isEmpty: true;
|
|
4485
|
-
};
|
|
4486
|
-
/**
|
|
4487
|
-
* Creates an Option from JSON string
|
|
4488
|
-
* @param json - The JSON string
|
|
4489
|
-
* @returns Option instance
|
|
4490
|
-
*/
|
|
4491
|
-
fromJSON: <T>(json: string) => Option<T>;
|
|
4492
|
-
/**
|
|
4493
|
-
* Creates an Option from YAML string
|
|
4494
|
-
* @param yaml - The YAML string
|
|
4495
|
-
* @returns Option instance
|
|
4496
|
-
*/
|
|
4497
|
-
fromYAML: <T>(yaml: string) => Option<T>;
|
|
4498
|
-
/**
|
|
4499
|
-
* Creates an Option from binary string
|
|
4500
|
-
* @param binary - The binary string
|
|
4501
|
-
* @returns Option instance
|
|
4502
|
-
*/
|
|
4503
|
-
fromBinary: <T>(binary: string) => Option<T>;
|
|
4504
|
-
};
|
|
4505
|
-
//#endregion
|
|
4506
|
-
//#region src/list/List.d.ts
|
|
4507
|
-
interface List<A> extends FunctypeCollection<A, "List">, Doable<A>, Reshapeable<A> {
|
|
4508
|
-
readonly length: number;
|
|
4509
|
-
readonly [Symbol.iterator]: () => Iterator<A>;
|
|
4510
|
-
map: <B>(f: (a: A) => B) => List<B>;
|
|
4511
|
-
ap: <B>(ff: List<(value: A) => B>) => List<B>;
|
|
4512
|
-
flatMap: <B>(f: (a: A) => Iterable<B>) => List<B>;
|
|
4513
|
-
flatMapAsync: <B>(f: (a: A) => PromiseLike<Iterable<B>>) => PromiseLike<List<B>>;
|
|
4514
|
-
filter<S extends A>(predicate: (a: A) => a is S): List<S>;
|
|
4515
|
-
filter(predicate: (a: A) => unknown): List<A>;
|
|
4516
|
-
filterNot: (p: (a: A) => boolean) => List<A>;
|
|
4517
|
-
/** @internal */
|
|
4518
|
-
filterType: <T extends Typeable<string, unknown>>(tag: string) => List<T & A>;
|
|
4519
|
-
remove: (value: A) => List<A>;
|
|
4520
|
-
removeAt: (index: number) => List<A>;
|
|
4521
|
-
add: (item: A) => List<A>;
|
|
4522
|
-
get: (index: number) => Option<A>;
|
|
4523
|
-
concat: (other: List<A>) => List<A>;
|
|
4524
|
-
/**
|
|
4525
|
-
* Pattern matches over the List, applying a handler function based on whether it's empty
|
|
4526
|
-
* @param patterns - Object with handler functions for Empty and NonEmpty variants
|
|
4527
|
-
* @returns The result of applying the matching handler function
|
|
4528
|
-
*/
|
|
4529
|
-
match<R$1>(patterns: {
|
|
4530
|
-
Empty: () => R$1;
|
|
4531
|
-
NonEmpty: (values: A[]) => R$1;
|
|
4532
|
-
}): R$1;
|
|
4533
|
-
}
|
|
4534
|
-
declare const List: (<A>(values?: Iterable<A>) => List<A>) & {
|
|
4535
|
-
/**
|
|
4536
|
-
* Creates a List from JSON string
|
|
4537
|
-
* @param json - The JSON string
|
|
4538
|
-
* @returns List instance
|
|
4539
|
-
*/
|
|
4540
|
-
fromJSON: <A>(json: string) => List<A>;
|
|
4541
|
-
/**
|
|
4542
|
-
* Creates a List from YAML string
|
|
4543
|
-
* @param yaml - The YAML string
|
|
4544
|
-
* @returns List instance
|
|
4545
|
-
*/
|
|
4546
|
-
fromYAML: <A>(yaml: string) => List<A>;
|
|
4547
|
-
/**
|
|
4548
|
-
* Creates a List from binary string
|
|
4549
|
-
* @param binary - The binary string
|
|
4550
|
-
* @returns List instance
|
|
4551
|
-
*/
|
|
4552
|
-
fromBinary: <A>(binary: string) => List<A>;
|
|
4553
|
-
};
|
|
4554
|
-
//#endregion
|
|
4555
3747
|
//#region src/collections/index.d.ts
|
|
4556
3748
|
/**
|
|
4557
3749
|
* Represents a collection with conversion capabilities
|
|
@@ -4581,8 +3773,8 @@ interface Collection<A> {
|
|
|
4581
3773
|
* }
|
|
4582
3774
|
* ```
|
|
4583
3775
|
*/
|
|
4584
|
-
interface FunctypeBase<A, Tag
|
|
4585
|
-
readonly _tag: Tag
|
|
3776
|
+
interface FunctypeBase<A, Tag extends string = string> extends AsyncMonad<A>, Traversable<A>, Serializable<A>, Foldable<A>, Typeable<Tag>, ContainerOps<A> {
|
|
3777
|
+
readonly _tag: Tag;
|
|
4586
3778
|
}
|
|
4587
3779
|
/**
|
|
4588
3780
|
* Interface for single-value containers like Option, Either, Try.
|
|
@@ -4591,9 +3783,9 @@ interface FunctypeBase<A, Tag$1 extends string = string> extends AsyncMonad<A>,
|
|
|
4591
3783
|
* @typeParam A - The type of value contained
|
|
4592
3784
|
* @typeParam Tag - The type tag for pattern matching
|
|
4593
3785
|
*/
|
|
4594
|
-
interface Functype<A, Tag
|
|
3786
|
+
interface Functype<A, Tag extends string = string> extends FunctypeBase<A, Tag>, Extractable<A>, Pipe<A>, Matchable<A, Tag> {
|
|
4595
3787
|
toValue(): {
|
|
4596
|
-
_tag: Tag
|
|
3788
|
+
_tag: Tag;
|
|
4597
3789
|
value: A;
|
|
4598
3790
|
};
|
|
4599
3791
|
}
|
|
@@ -4604,372 +3796,13 @@ interface Functype<A, Tag$1 extends string = string> extends FunctypeBase<A, Tag
|
|
|
4604
3796
|
* @typeParam A - The element type of the collection
|
|
4605
3797
|
* @typeParam Tag - The type tag for pattern matching
|
|
4606
3798
|
*/
|
|
4607
|
-
interface FunctypeCollection<A, Tag
|
|
3799
|
+
interface FunctypeCollection<A, Tag extends string = string> extends Omit<FunctypeBase<A, Tag>, "flatMapAsync" | "flatMap">, Iterable<A>, Pipe<A[]>, Collection<A>, CollectionOps<A, FunctypeCollection<A, Tag>> {
|
|
4608
3800
|
toValue(): {
|
|
4609
|
-
_tag: Tag
|
|
3801
|
+
_tag: Tag;
|
|
4610
3802
|
value: A[];
|
|
4611
3803
|
};
|
|
4612
|
-
flatMap<B extends Type>(f: (value: A) => Iterable<B>): FunctypeCollection<B, Tag
|
|
4613
|
-
flatMapAsync<B extends Type>(f: (value: A) => PromiseLike<Iterable<B>>): PromiseLike<FunctypeCollection<B, Tag
|
|
4614
|
-
}
|
|
4615
|
-
//#endregion
|
|
4616
|
-
//#region src/either/Either.d.ts
|
|
4617
|
-
/**
|
|
4618
|
-
* Either type module
|
|
4619
|
-
* @module Either
|
|
4620
|
-
* @category Core
|
|
4621
|
-
*/
|
|
4622
|
-
interface Either<L extends Type, R$1 extends Type> extends FunctypeBase<R$1, "Left" | "Right">, Promisable<R$1>, Doable<R$1>, Reshapeable<R$1>, Extractable<R$1> {
|
|
4623
|
-
readonly _tag: "Left" | "Right";
|
|
4624
|
-
value: L | R$1;
|
|
4625
|
-
isLeft(): this is Either<L, R$1> & {
|
|
4626
|
-
readonly _tag: "Left";
|
|
4627
|
-
value: L;
|
|
4628
|
-
};
|
|
4629
|
-
isRight(): this is Either<L, R$1> & {
|
|
4630
|
-
readonly _tag: "Right";
|
|
4631
|
-
value: R$1;
|
|
4632
|
-
};
|
|
4633
|
-
orElse: (defaultValue: R$1) => R$1;
|
|
4634
|
-
orThrow: (error?: Error) => R$1;
|
|
4635
|
-
or(alternative: Either<L, R$1>): Either<L, R$1>;
|
|
4636
|
-
orNull: () => R$1 | null;
|
|
4637
|
-
orUndefined: () => R$1 | undefined;
|
|
4638
|
-
readonly map: <U extends Type>(f: (value: R$1) => U) => Either<L, U>;
|
|
4639
|
-
ap: <U extends Type>(ff: Either<L, (value: R$1) => U>) => Either<L, U>;
|
|
4640
|
-
merge: <L1 extends Type, R1 extends Type>(other: Either<L1, R1>) => Either<L | L1, [R$1, R1]>;
|
|
4641
|
-
mapAsync: <U extends Type>(f: (value: R$1) => Promise<U>) => Promise<Either<L, U>>;
|
|
4642
|
-
flatMap: <U extends Type>(f: (value: R$1) => Either<L, U>) => Either<L, U>;
|
|
4643
|
-
flatMapAsync: <U extends Type>(f: (value: R$1) => Promise<Either<L, U>>) => Promise<Either<L, U>>;
|
|
4644
|
-
toOption: () => Option<R$1>;
|
|
4645
|
-
toList: () => List<R$1>;
|
|
4646
|
-
toString: () => string;
|
|
4647
|
-
[Symbol.iterator]: () => Iterator<R$1>;
|
|
4648
|
-
yield: () => Generator<R$1, void, unknown>;
|
|
4649
|
-
traverse: <U extends Type>(f: (value: R$1) => Either<L, U>) => Either<L, U[]>;
|
|
4650
|
-
lazyMap: <U extends Type>(f: (value: R$1) => U) => Generator<Either<L, U>, void, unknown>;
|
|
4651
|
-
tap: (f: (value: R$1) => void) => Either<L, R$1>;
|
|
4652
|
-
tapLeft: (f: (value: L) => void) => Either<L, R$1>;
|
|
4653
|
-
mapLeft: <L2 extends Type>(f: (value: L) => L2) => Either<L2, R$1>;
|
|
4654
|
-
bimap: <L2 extends Type, R2 extends Type>(fl: (value: L) => L2, fr: (value: R$1) => R2) => Either<L2, R2>;
|
|
4655
|
-
fold: <T extends Type>(onLeft: (value: L) => T, onRight: (value: R$1) => T) => T;
|
|
4656
|
-
swap: () => Either<R$1, L>;
|
|
4657
|
-
/**
|
|
4658
|
-
* Pipes the value through the provided function based on whether this is a Left or Right
|
|
4659
|
-
* @param onLeft - The function to apply if this is a Left
|
|
4660
|
-
* @param onRight - The function to apply if this is a Right
|
|
4661
|
-
* @returns The result of applying the appropriate function
|
|
4662
|
-
*/
|
|
4663
|
-
pipeEither<U extends Type>(onLeft: (value: L) => U, onRight: (value: R$1) => U): U;
|
|
4664
|
-
/**
|
|
4665
|
-
* Pipes the Either value through the provided function
|
|
4666
|
-
* @param f - The function to apply to the value (Left or Right)
|
|
4667
|
-
* @returns The result of applying the function to the value
|
|
4668
|
-
*/
|
|
4669
|
-
pipe<U extends Type>(f: (value: L | R$1) => U): U;
|
|
4670
|
-
/**
|
|
4671
|
-
* Pattern matches over the Either, applying a handler function based on the variant
|
|
4672
|
-
* @param patterns - Object with handler functions for Left and Right variants
|
|
4673
|
-
* @returns The result of applying the matching handler function
|
|
4674
|
-
*/
|
|
4675
|
-
match<T>(patterns: {
|
|
4676
|
-
Left: (value: L) => T;
|
|
4677
|
-
Right: (value: R$1) => T;
|
|
4678
|
-
}): T;
|
|
4679
|
-
/**
|
|
4680
|
-
* Returns the value and tag for inspection
|
|
4681
|
-
*/
|
|
4682
|
-
toValue(): {
|
|
4683
|
-
_tag: "Left" | "Right";
|
|
4684
|
-
value: L | R$1;
|
|
4685
|
-
};
|
|
4686
|
-
/**
|
|
4687
|
-
* Custom JSON serialization that excludes getter properties
|
|
4688
|
-
*/
|
|
4689
|
-
toJSON(): {
|
|
4690
|
-
_tag: "Left" | "Right";
|
|
4691
|
-
value: L | R$1;
|
|
4692
|
-
};
|
|
4693
|
-
}
|
|
4694
|
-
type TestEither<L extends Type, R$1 extends Type> = Either<L, R$1> & AsyncMonad<R$1>;
|
|
4695
|
-
declare const Right: <L extends Type, R$1 extends Type>(value: R$1) => Either<L, R$1>;
|
|
4696
|
-
declare const Left: <L extends Type, R$1 extends Type>(value: L) => Either<L, R$1>;
|
|
4697
|
-
declare const isRight: <L extends Type, R$1 extends Type>(either: Either<L, R$1>) => either is Either<L, R$1> & {
|
|
4698
|
-
value: R$1;
|
|
4699
|
-
};
|
|
4700
|
-
declare const isLeft: <L extends Type, R$1 extends Type>(either: Either<L, R$1>) => either is Either<L, R$1> & {
|
|
4701
|
-
value: L;
|
|
4702
|
-
};
|
|
4703
|
-
declare const tryCatch: <L extends Type, R$1 extends Type>(f: () => R$1, onError: (error: unknown) => L) => Either<L, R$1>;
|
|
4704
|
-
declare const TypeCheckRight: <L extends Type, R$1 extends Type>(value: R$1) => TestEither<L, R$1>;
|
|
4705
|
-
declare const TypeCheckLeft: <L extends Type, R$1 extends Type>(value: L) => TestEither<L, R$1>;
|
|
4706
|
-
declare const tryCatchAsync: <L extends Type, R$1 extends Type>(f: () => Promise<R$1>, onError: (error: unknown) => L) => Promise<Either<L, R$1>>;
|
|
4707
|
-
declare const Either: (<L extends Type, R$1 extends Type>(value: R$1 | L, isRight: boolean) => Either<L, R$1>) & {
|
|
4708
|
-
/**
|
|
4709
|
-
* Creates a Left instance
|
|
4710
|
-
* @param value - The left value
|
|
4711
|
-
* @returns Left Either
|
|
4712
|
-
*/
|
|
4713
|
-
left: <L extends Type, R$1 extends Type>(value: L) => Either<L, R$1>;
|
|
4714
|
-
/**
|
|
4715
|
-
* Creates a Right instance
|
|
4716
|
-
* @param value - The right value
|
|
4717
|
-
* @returns Right Either
|
|
4718
|
-
*/
|
|
4719
|
-
right: <L extends Type, R$1 extends Type>(value: R$1) => Either<L, R$1>;
|
|
4720
|
-
/**
|
|
4721
|
-
* Type guard to check if an Either is Right
|
|
4722
|
-
* @param either - The Either to check
|
|
4723
|
-
* @returns True if Either is Right
|
|
4724
|
-
*/
|
|
4725
|
-
isRight: <L extends Type, R$1 extends Type>(either: Either<L, R$1>) => either is Either<L, R$1> & {
|
|
4726
|
-
value: R$1;
|
|
4727
|
-
};
|
|
4728
|
-
/**
|
|
4729
|
-
* Type guard to check if an Either is Left
|
|
4730
|
-
* @param either - The Either to check
|
|
4731
|
-
* @returns True if Either is Left
|
|
4732
|
-
*/
|
|
4733
|
-
isLeft: <L extends Type, R$1 extends Type>(either: Either<L, R$1>) => either is Either<L, R$1> & {
|
|
4734
|
-
value: L;
|
|
4735
|
-
};
|
|
4736
|
-
/**
|
|
4737
|
-
* Combines an array of Eithers into a single Either containing an array
|
|
4738
|
-
* @param eithers - Array of Either values
|
|
4739
|
-
* @returns Either with array of values or first Left encountered
|
|
4740
|
-
*/
|
|
4741
|
-
sequence: <L extends Type, R$1 extends Type>(eithers: Either<L, R$1>[]) => Either<L, R$1[]>;
|
|
4742
|
-
/**
|
|
4743
|
-
* Maps an array through a function that returns Either, then sequences the results
|
|
4744
|
-
* @param arr - Array of values
|
|
4745
|
-
* @param f - Function that returns Either
|
|
4746
|
-
* @returns Either with array of results or first Left encountered
|
|
4747
|
-
*/
|
|
4748
|
-
traverse: <L extends Type, R$1 extends Type, U extends Type>(arr: R$1[], f: (value: R$1) => Either<L, U>) => Either<L, U[]>;
|
|
4749
|
-
/**
|
|
4750
|
-
* Creates an Either from a nullable value
|
|
4751
|
-
* @param value - The value that might be null or undefined
|
|
4752
|
-
* @param leftValue - The value to use for Left if value is null/undefined
|
|
4753
|
-
* @returns Right if value is not null/undefined, Left otherwise
|
|
4754
|
-
*/
|
|
4755
|
-
fromNullable: <L extends Type, R$1 extends Type>(value: R$1 | null | undefined, leftValue: L) => Either<L, R$1>;
|
|
4756
|
-
/**
|
|
4757
|
-
* Creates an Either based on a predicate
|
|
4758
|
-
* @param value - The value to test
|
|
4759
|
-
* @param predicate - The predicate function
|
|
4760
|
-
* @param leftValue - The value to use for Left if predicate fails
|
|
4761
|
-
* @returns Right if predicate passes, Left otherwise
|
|
4762
|
-
*/
|
|
4763
|
-
fromPredicate: <L extends Type, R$1 extends Type>(value: R$1, predicate: (value: R$1) => boolean, leftValue: L) => Either<L, R$1>;
|
|
4764
|
-
/**
|
|
4765
|
-
* Applicative apply - applies a wrapped function to a wrapped value
|
|
4766
|
-
* @param eitherF - Either containing a function
|
|
4767
|
-
* @param eitherV - Either containing a value
|
|
4768
|
-
* @returns Either with function applied to value
|
|
4769
|
-
*/
|
|
4770
|
-
ap: <L extends Type, R$1 extends Type, U extends Type>(eitherF: Either<L, (value: R$1) => U>, eitherV: Either<L, R$1>) => Either<L, U>;
|
|
4771
|
-
/**
|
|
4772
|
-
* Creates an Either from a Promise
|
|
4773
|
-
* @param promise - The Promise to convert
|
|
4774
|
-
* @param onRejected - Function to convert rejection reason to Left value
|
|
4775
|
-
* @returns Promise that resolves to Either
|
|
4776
|
-
*/
|
|
4777
|
-
fromPromise: <L, R$1>(promise: Promise<R$1>, onRejected: (reason: unknown) => L) => Promise<Either<L, R$1>>;
|
|
4778
|
-
/**
|
|
4779
|
-
* Creates an Either from JSON string
|
|
4780
|
-
* @param json - The JSON string
|
|
4781
|
-
* @returns Either instance
|
|
4782
|
-
*/
|
|
4783
|
-
fromJSON: <L extends Type, R$1 extends Type>(json: string) => Either<L, R$1>;
|
|
4784
|
-
/**
|
|
4785
|
-
* Creates an Either from YAML string
|
|
4786
|
-
* @param yaml - The YAML string
|
|
4787
|
-
* @returns Either instance
|
|
4788
|
-
*/
|
|
4789
|
-
fromYAML: <L extends Type, R$1 extends Type>(yaml: string) => Either<L, R$1>;
|
|
4790
|
-
/**
|
|
4791
|
-
* Creates an Either from binary string
|
|
4792
|
-
* @param binary - The binary string
|
|
4793
|
-
* @returns Either instance
|
|
4794
|
-
*/
|
|
4795
|
-
fromBinary: <L extends Type, R$1 extends Type>(binary: string) => Either<L, R$1>;
|
|
4796
|
-
};
|
|
4797
|
-
//#endregion
|
|
4798
|
-
//#region src/do/index.d.ts
|
|
4799
|
-
type OptionLike = {
|
|
4800
|
-
_tag: "Some" | "None";
|
|
4801
|
-
isSome(): boolean;
|
|
4802
|
-
get(): unknown;
|
|
4803
|
-
};
|
|
4804
|
-
type EitherLike = {
|
|
4805
|
-
_tag: "Left" | "Right";
|
|
4806
|
-
isLeft(): boolean;
|
|
4807
|
-
isRight(): boolean;
|
|
4808
|
-
value: unknown;
|
|
4809
|
-
};
|
|
4810
|
-
type ListLike = {
|
|
4811
|
-
_tag: "List";
|
|
4812
|
-
toArray(): unknown[];
|
|
4813
|
-
};
|
|
4814
|
-
type TryLike = {
|
|
4815
|
-
_tag: "Success" | "Failure";
|
|
4816
|
-
isSuccess(): boolean;
|
|
4817
|
-
get(): unknown;
|
|
4818
|
-
};
|
|
4819
|
-
/**
|
|
4820
|
-
* Executes a generator-based monadic comprehension
|
|
4821
|
-
* Returns the same monad type as the first yielded monad (Scala semantics)
|
|
4822
|
-
*
|
|
4823
|
-
* - Option comprehensions return Option (None on short-circuit)
|
|
4824
|
-
* - Either comprehensions return Either (Left with error on short-circuit)
|
|
4825
|
-
* - List comprehensions return List (empty or cartesian product)
|
|
4826
|
-
* - Try comprehensions return Try (Failure with error on short-circuit)
|
|
4827
|
-
*
|
|
4828
|
-
* Type Inference Notes:
|
|
4829
|
-
* - TypeScript infers the correct return type for homogeneous comprehensions
|
|
4830
|
-
* - For mixed monad types, TypeScript returns a union type
|
|
4831
|
-
* - Use DoTyped<T> or type assertions for mixed scenarios
|
|
4832
|
-
*
|
|
4833
|
-
* @example
|
|
4834
|
-
* ```typescript
|
|
4835
|
-
* // Option comprehension returns Option:
|
|
4836
|
-
* const result = Do(function* () {
|
|
4837
|
-
* const x = yield* $(Option(5));
|
|
4838
|
-
* const y = yield* $(Option(10));
|
|
4839
|
-
* return x + y;
|
|
4840
|
-
* });
|
|
4841
|
-
* // result: Option(15)
|
|
4842
|
-
*
|
|
4843
|
-
* // Either comprehension returns Either:
|
|
4844
|
-
* const result = Do(function* () {
|
|
4845
|
-
* const x = yield* $(Right(5));
|
|
4846
|
-
* const y = yield* $(Left("error"));
|
|
4847
|
-
* return x + y;
|
|
4848
|
-
* });
|
|
4849
|
-
* // result: Left("error") - error is preserved
|
|
4850
|
-
*
|
|
4851
|
-
* // List comprehension returns List with cartesian product:
|
|
4852
|
-
* const result = Do(function* () {
|
|
4853
|
-
* const x = yield* $(List([1, 2]));
|
|
4854
|
-
* const y = yield* $(List([3, 4]));
|
|
4855
|
-
* return x + y;
|
|
4856
|
-
* });
|
|
4857
|
-
* // result: List([4, 5, 5, 6])
|
|
4858
|
-
*
|
|
4859
|
-
* // Mixed types - use type assertion or DoTyped:
|
|
4860
|
-
* const result = Do(function* () {
|
|
4861
|
-
* const x = yield* $(Option(5));
|
|
4862
|
-
* const y = yield* $(Right<string, number>(10));
|
|
4863
|
-
* return x + y;
|
|
4864
|
-
* }) as Option<number>;
|
|
4865
|
-
* // result: Option(15)
|
|
4866
|
-
* ```
|
|
4867
|
-
*
|
|
4868
|
-
* @param gen - Generator function that yields monads and returns a result
|
|
4869
|
-
* @returns The same monad type as the first yield
|
|
4870
|
-
*/
|
|
4871
|
-
declare function Do<T>(gen: () => Generator<OptionLike, T, unknown>): Option<T>;
|
|
4872
|
-
declare function Do<L, R$1>(gen: () => Generator<EitherLike, R$1, unknown>): Either<L, R$1>;
|
|
4873
|
-
declare function Do<T>(gen: () => Generator<ListLike, T, unknown>): List<T>;
|
|
4874
|
-
declare function Do<T>(gen: () => Generator<TryLike, T, unknown>): Try<T>;
|
|
4875
|
-
declare function Do<T>(gen: () => Generator<OptionLike | EitherLike | ListLike | TryLike, T, unknown>): Reshapeable<T>;
|
|
4876
|
-
declare function Do<T>(gen: () => Generator<unknown, T, unknown>): unknown;
|
|
4877
|
-
/**
|
|
4878
|
-
* Executes an async generator-based monadic comprehension
|
|
4879
|
-
* Returns the same monad type as the first yielded monad
|
|
4880
|
-
*
|
|
4881
|
-
* @example
|
|
4882
|
-
* ```typescript
|
|
4883
|
-
* const result = await DoAsync(async function* () {
|
|
4884
|
-
* const user = yield* $(await fetchUser(id)); // Promise<Option<User>> → User
|
|
4885
|
-
* const profile = yield* $(await getProfile(user)); // Promise<Either<Error, Profile>> → Profile
|
|
4886
|
-
* return { user, profile };
|
|
4887
|
-
* });
|
|
4888
|
-
* // result type matches first yield
|
|
4889
|
-
* ```
|
|
4890
|
-
*
|
|
4891
|
-
* @param gen - Async generator function that yields monads/promises and returns a result
|
|
4892
|
-
* @returns Promise of the same monad type as first yield
|
|
4893
|
-
*/
|
|
4894
|
-
declare function DoAsync<T>(gen: () => AsyncGenerator<OptionLike, T, unknown>): Promise<Option<T>>;
|
|
4895
|
-
declare function DoAsync<L, R$1>(gen: () => AsyncGenerator<EitherLike, R$1, unknown>): Promise<Either<L, R$1>>;
|
|
4896
|
-
declare function DoAsync<T>(gen: () => AsyncGenerator<ListLike, T, unknown>): Promise<List<T>>;
|
|
4897
|
-
declare function DoAsync<T>(gen: () => AsyncGenerator<TryLike, T, unknown>): Promise<Try<T>>;
|
|
4898
|
-
declare function DoAsync<T>(gen: () => AsyncGenerator<OptionLike | EitherLike | ListLike | TryLike, T, unknown>): Promise<Reshapeable<T>>;
|
|
4899
|
-
declare function DoAsync<T>(gen: () => AsyncGenerator<unknown, T, unknown>): Promise<unknown>;
|
|
4900
|
-
/**
|
|
4901
|
-
* Helper function to check if a value implements the Doable interface
|
|
4902
|
-
* @param value - Value to check
|
|
4903
|
-
* @returns True if the value implements Doable
|
|
4904
|
-
*/
|
|
4905
|
-
declare function isDoCapable<T>(value: unknown): value is Doable<T>;
|
|
4906
|
-
/**
|
|
4907
|
-
* Manually unwrap a monad using the Doable interface
|
|
4908
|
-
* Useful for testing or when you need to unwrap outside of a Do-comprehension
|
|
4909
|
-
*
|
|
4910
|
-
* @param monad - Monad to unwrap
|
|
4911
|
-
* @returns The unwrapped value
|
|
4912
|
-
* @throws Error if the monad cannot be unwrapped
|
|
4913
|
-
*/
|
|
4914
|
-
declare function unwrap<T>(monad: Doable<T>): T;
|
|
4915
|
-
/**
|
|
4916
|
-
* Type helper for Do-notation generators.
|
|
4917
|
-
* Provides better type hints in IDEs.
|
|
4918
|
-
*
|
|
4919
|
-
* @example
|
|
4920
|
-
* ```typescript
|
|
4921
|
-
* const result = Do(function* (): DoGenerator<number> {
|
|
4922
|
-
* const x = yield* $(List([1, 2])) // x is still unknown but return type is clear
|
|
4923
|
-
* const y = yield* $(List([3, 4]))
|
|
4924
|
-
* return x + y
|
|
4925
|
-
* })
|
|
4926
|
-
* ```
|
|
4927
|
-
*/
|
|
4928
|
-
type DoGenerator<T, TYield = unknown> = Generator<TYield, T, unknown>;
|
|
4929
|
-
/**
|
|
4930
|
-
* Extracts values from monads in Do-notation with type inference.
|
|
4931
|
-
* The '$' symbol is the universal extraction operator in functional programming.
|
|
4932
|
-
*
|
|
4933
|
-
* @example
|
|
4934
|
-
* ```typescript
|
|
4935
|
-
* const result = Do(function* () {
|
|
4936
|
-
* const x = yield* $(Option(5)) // x: number
|
|
4937
|
-
* const y = yield* $(List([1, 2, 3])) // y: number (for cartesian product)
|
|
4938
|
-
* const name = yield* $(Right("Alice")) // name: string
|
|
4939
|
-
* return `${name}: ${x + y}`
|
|
4940
|
-
* })
|
|
4941
|
-
* ```
|
|
4942
|
-
*
|
|
4943
|
-
* @param monad - Any monad that can be unwrapped (Option, Either, List, Try, etc.)
|
|
4944
|
-
* @returns A generator that yields the monad and returns its extracted value
|
|
4945
|
-
*/
|
|
4946
|
-
declare function $<T>(monad: Option<T>): Generator<Option<T>, T, T>;
|
|
4947
|
-
declare function $<L, R$1>(monad: Either<L, R$1>): Generator<Either<L, R$1>, R$1, R$1>;
|
|
4948
|
-
declare function $<T>(monad: List<T>): Generator<List<T>, T, T>;
|
|
4949
|
-
declare function $<T>(monad: Try<T>): Generator<Try<T>, T, T>;
|
|
4950
|
-
declare function $<T>(monad: Doable<T>): Generator<Doable<T>, T, T>;
|
|
4951
|
-
declare function $<M>(monad: M): Generator<M, InferYieldType<M>, InferYieldType<M>>;
|
|
4952
|
-
type InferYieldType<M> = M extends {
|
|
4953
|
-
isSome(): boolean;
|
|
4954
|
-
get(): infer T;
|
|
4955
|
-
} ? T : M extends {
|
|
4956
|
-
isRight(): boolean;
|
|
4957
|
-
value: infer R;
|
|
4958
|
-
} ? R : M extends {
|
|
4959
|
-
toArray(): (infer T)[];
|
|
4960
|
-
} ? T : M extends {
|
|
4961
|
-
isSuccess(): boolean;
|
|
4962
|
-
get(): infer T;
|
|
4963
|
-
} ? T : M extends Doable<infer T> ? T : unknown;
|
|
4964
|
-
declare const NoneError: (message?: string) => Error;
|
|
4965
|
-
interface LeftErrorType<L> extends Error {
|
|
4966
|
-
value: L;
|
|
4967
|
-
}
|
|
4968
|
-
declare const LeftError: <L>(value: L, message?: string) => LeftErrorType<L>;
|
|
4969
|
-
declare const EmptyListError: (message?: string) => Error;
|
|
4970
|
-
interface FailureErrorType extends Error {
|
|
4971
|
-
cause: Error;
|
|
3804
|
+
flatMap<B extends Type>(f: (value: A) => Iterable<B>): FunctypeCollection<B, Tag>;
|
|
3805
|
+
flatMapAsync<B extends Type>(f: (value: A) => PromiseLike<Iterable<B>>): PromiseLike<FunctypeCollection<B, Tag>>;
|
|
4972
3806
|
}
|
|
4973
|
-
declare const FailureError: (cause: Error, message?: string) => FailureErrorType;
|
|
4974
3807
|
//#endregion
|
|
4975
|
-
export {
|
|
3808
|
+
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 };
|