functype 0.11.2 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,16 +1,146 @@
1
1
  import { Brand } from './branded/index.js';
2
2
  export { BrandedBoolean, BrandedNumber, BrandedString, ExtractBrand, Unbrand, createBrander, hasBrand, unbrand } from './branded/index.js';
3
- import { O as Option, E as Either, L as List, F as FunctypeBase, a as Extractable, T as Traversable, M as Matchable } from './Either-DgkP4DUw.js';
4
- export { A as Applicative, q as AsyncMonad, C as Collection, o as CollectionOps, p as ContainerOps, r as Functor, j as Functype, k as FunctypeCollection, c as Left, l as MatchableUtils, s as Monad, N as None, m as OptionConstructor, P as Promisable, R as Right, n as Set, S as Some, b as TestEither, f as TypeCheckLeft, e as TypeCheckRight, h as isExtractable, d as isLeft, i as isRight, t as tryCatch, g as tryCatchAsync } from './Either-DgkP4DUw.js';
5
- import { T as Type, a as Typeable, F as Foldable, P as Pipe, S as Serializable } from './Serializable-CK9upOU0.js';
6
- export { E as ExtractTag, b as SerializationMethods, c as TypeableParams, i as isTypeable } from './Serializable-CK9upOU0.js';
3
+ import { L as List, O as Option, E as Either, D as DO_PROTOCOL, a as DoResult, T as Try, F as FunctypeBase, b as Extractable, c as Traversable, M as Matchable } from './Either-D4P39LPj.js';
4
+ export { A as Applicative, v as AsyncMonad, C as Collection, s as CollectionOps, u as ContainerOps, d as DoProtocol, w as Functor, m as Functype, n as FunctypeCollection, f as Left, o as MatchableUtils, x as Monad, N as None, p as OptionConstructor, P as Promisable, R as Right, q as Set, S as Some, e as TestEither, j as TypeCheckLeft, h as TypeCheckRight, r as TypeNames, l as isExtractable, g as isLeft, i as isRight, t as tryCatch, k as tryCatchAsync } from './Either-D4P39LPj.js';
5
+ import { T as Type, F as Foldable, P as Pipe, S as Serializable, a as Typeable } from './Typeable-CitTP1ay.js';
6
+ export { E as ExtractTag, b as SerializationMethods, c as TypeableParams, i as isTypeable } from './Typeable-CitTP1ay.js';
7
7
  import { FPromise } from './fpromise/index.js';
8
8
  export { ErrorContext, FPromiseCompanion } from './fpromise/index.js';
9
- import { Try } from './try/index.js';
10
- export { TypeNames } from './try/index.js';
9
+ export { $, Do, DoAsync, DoGenerator, EmptyListError, FailureError, FailureErrorType, LeftError, LeftErrorType, NoneError, isDoCapable, unwrap } from './do/index.js';
11
10
  export { Map, SafeTraversable } from './map/index.js';
12
11
  export { Tuple } from './tuple/index.js';
13
12
 
13
+ /**
14
+ * LazyList provides lazy evaluation for list operations.
15
+ * Operations are deferred until the list is materialized.
16
+ *
17
+ * @example
18
+ * // Basic lazy evaluation
19
+ * const result = LazyList([1, 2, 3, 4, 5])
20
+ * .map(x => x * 2)
21
+ * .filter(x => x > 5)
22
+ * .toArray() // [6, 8, 10]
23
+ *
24
+ * @example
25
+ * // Infinite sequences with take
26
+ * const fibonacci = LazyList.iterate([0, 1], ([a, b]) => [b, a + b])
27
+ * .map(([a]) => a)
28
+ * .take(10)
29
+ * .toArray() // [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
30
+ */
31
+ interface LazyList<A extends Type> extends Foldable<A>, Pipe<LazyList<A>>, Serializable<LazyList<A>>, Typeable<"LazyList"> {
32
+ [Symbol.iterator](): Iterator<A>;
33
+ map<B extends Type>(f: (a: A) => B): LazyList<B>;
34
+ flatMap<B extends Type>(f: (a: A) => LazyList<B>): LazyList<B>;
35
+ filter(predicate: (a: A) => boolean): LazyList<A>;
36
+ take(n: number): LazyList<A>;
37
+ drop(n: number): LazyList<A>;
38
+ takeWhile(predicate: (a: A) => boolean): LazyList<A>;
39
+ dropWhile(predicate: (a: A) => boolean): LazyList<A>;
40
+ concat(other: LazyList<A>): LazyList<A>;
41
+ zip<B extends Type>(other: LazyList<B>): LazyList<[A, B]>;
42
+ toList(): List<A>;
43
+ toArray(): A[];
44
+ forEach(f: (a: A) => void): void;
45
+ reduce<B extends Type>(f: (acc: B, a: A) => B, initial: B): B;
46
+ find(predicate: (a: A) => boolean): Option<A>;
47
+ some(predicate: (a: A) => boolean): boolean;
48
+ every(predicate: (a: A) => boolean): boolean;
49
+ count(): number;
50
+ first(): Option<A>;
51
+ last(): Option<A>;
52
+ toString(): string;
53
+ }
54
+ /**
55
+ * Lazy list implementation for efficient deferred computation
56
+ * @example
57
+ * // Process large datasets efficiently
58
+ * const result = LazyList.range(1, 1000000)
59
+ * .filter(x => x % 2 === 0)
60
+ * .map(x => x * x)
61
+ * .take(5)
62
+ * .toArray() // [4, 16, 36, 64, 100]
63
+ *
64
+ * @example
65
+ * // Infinite sequences
66
+ * const primes = LazyList.iterate(2, n => n + 1)
67
+ * .filter(isPrime)
68
+ * .take(10)
69
+ * .toArray() // First 10 prime numbers
70
+ *
71
+ * @example
72
+ * // Combining operations
73
+ * const evens = LazyList.range(0, 100, 2)
74
+ * const odds = LazyList.range(1, 100, 2)
75
+ * const combined = evens.zip(odds)
76
+ * .map(([e, o]) => e + o)
77
+ * .take(5)
78
+ * .toArray() // [1, 5, 9, 13, 17]
79
+ */
80
+ declare const LazyList: (<A extends Type>(iterable: Iterable<A>) => LazyList<A>) & {
81
+ /**
82
+ * Create an empty LazyList
83
+ * @example
84
+ * const empty = LazyList.empty<number>()
85
+ * empty.toArray() // []
86
+ */
87
+ empty: <A extends Type>() => LazyList<A>;
88
+ /**
89
+ * Create a LazyList from a single value
90
+ * @example
91
+ * const single = LazyList.of(42)
92
+ * .map(x => x * 2)
93
+ * .toArray() // [84]
94
+ */
95
+ of: <A extends Type>(value: A) => LazyList<A>;
96
+ /**
97
+ * Create a LazyList from multiple values
98
+ */
99
+ from: <A extends Type>(...values: A[]) => LazyList<A>;
100
+ /**
101
+ * Create an infinite LazyList by repeatedly applying a function
102
+ * @example
103
+ * // Powers of 2
104
+ * const powers = LazyList.iterate(1, x => x * 2)
105
+ * .take(10)
106
+ * .toArray() // [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
107
+ *
108
+ * @example
109
+ * // Fibonacci sequence
110
+ * const fib = LazyList.iterate([0, 1], ([a, b]) => [b, a + b])
111
+ * .map(([a]) => a)
112
+ * .take(8)
113
+ * .toArray() // [0, 1, 1, 2, 3, 5, 8, 13]
114
+ */
115
+ iterate: <A extends Type>(initial: A, f: (a: A) => A) => LazyList<A>;
116
+ /**
117
+ * Create an infinite LazyList by repeatedly calling a function
118
+ */
119
+ generate: <A extends Type>(f: () => A) => LazyList<A>;
120
+ /**
121
+ * Create a LazyList of numbers from start to end (exclusive)
122
+ * @example
123
+ * LazyList.range(1, 6).toArray() // [1, 2, 3, 4, 5]
124
+ * LazyList.range(0, 10, 2).toArray() // [0, 2, 4, 6, 8]
125
+ * LazyList.range(10, 0, -1).toArray() // [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
126
+ *
127
+ * @example
128
+ * // Sum of squares from 1 to 100
129
+ * const sum = LazyList.range(1, 101)
130
+ * .map(x => x * x)
131
+ * .reduce((a, b) => a + b, 0) // 338350
132
+ */
133
+ range: (start: number, end: number, step?: number) => LazyList<number>;
134
+ /**
135
+ * Create a LazyList that repeats a value n times (or infinitely if n is not provided)
136
+ */
137
+ repeat: <A extends Type>(value: A, n?: number) => LazyList<A>;
138
+ /**
139
+ * Create a LazyList that cycles through an iterable infinitely
140
+ */
141
+ cycle: <A extends Type>(iterable: Iterable<A>) => LazyList<A>;
142
+ };
143
+
14
144
  interface ValidatedBrandCompanion<K extends string, T> {
15
145
  readonly brand: K;
16
146
  readonly validate: (value: T) => boolean;
@@ -534,11 +664,13 @@ declare const Match: (<T extends Type, R extends Type>(value: T) => Match<T, R>)
534
664
 
535
665
  /**
536
666
  * Base Object from which most other objects inherit
667
+ * Now includes automatic Do-notation support via DO_PROTOCOL
537
668
  * @param type - The type name for the object
538
669
  * @param body - The implementation body
539
670
  */
540
- declare function Base<T>(type: string, body: T): T & {
671
+ declare function Base<T extends Record<string, unknown>>(type: string, body: T): T & {
541
672
  toString(): string;
673
+ [DO_PROTOCOL](): DoResult<unknown>;
542
674
  _tag: string;
543
675
  };
544
676
 
@@ -639,6 +771,21 @@ interface TaskSuccess<T> extends TaskOutcome<T> {
639
771
  */
640
772
  declare const TaskSuccess: <T>(data: T, params?: TaskParams) => TaskSuccess<T>;
641
773
  type TaskResult<T> = Promise<TaskOutcome<T>>;
774
+ /**
775
+ * Ok constructor - Creates a successful TaskOutcome
776
+ * Alias for TaskSuccess for cleaner, more concise code
777
+ * @param value - The successful value
778
+ * @param params - Optional task parameters
779
+ */
780
+ declare const Ok: <T>(value: T, params?: TaskParams) => TaskSuccess<T>;
781
+ /**
782
+ * Err constructor - Creates a failed TaskOutcome
783
+ * Alias for TaskFailure for cleaner, more concise code
784
+ * @param error - The error value
785
+ * @param data - Optional additional error data
786
+ * @param params - Optional task parameters
787
+ */
788
+ declare const Err: <T>(error: unknown, data?: unknown, params?: TaskParams) => TaskFailure<T>;
642
789
  /**
643
790
  * The CancellationToken is a control structure that allows long-running tasks to be cancelled
644
791
  * Cancellation is cooperative, meaning the task must check the token and respond to cancellation requests
@@ -679,7 +826,7 @@ declare const Task: (<T = unknown>(params?: TaskParams) => {
679
826
  * @param f - Optional finally handler function
680
827
  * @param cancellationToken - Optional token for cancellation support
681
828
  */
682
- Async: <U = T>(t: () => U | Promise<U>, e?: (error: unknown) => unknown, f?: () => Promise<void> | void, cancellationToken?: CancellationToken) => FPromise<U>;
829
+ Async: <U = T>(t: () => U | Promise<U> | TaskOutcome<U> | Promise<TaskOutcome<U>>, e?: (error: unknown) => unknown | TaskOutcome<U>, f?: () => Promise<void> | void, cancellationToken?: CancellationToken) => FPromise<TaskOutcome<U>>;
683
830
  /**
684
831
  * Run a synchronous operation with explicit try/catch/finally semantics
685
832
  * Returns a TaskOutcome for functional error handling
@@ -699,8 +846,9 @@ declare const Task: (<T = unknown>(params?: TaskParams) => {
699
846
  * @param f - Optional finally handler function
700
847
  * @param cancellationToken - Optional token for cancellation support
701
848
  */
702
- AsyncWithProgress: <U = T>(t: (updateProgress: (percent: number) => void) => U | Promise<U>, onProgress: (percent: number) => void, e?: (error: unknown) => unknown, f?: () => Promise<void> | void, cancellationToken?: CancellationToken) => FPromise<U>;
849
+ 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) => FPromise<TaskOutcome<U>>;
703
850
  toString(): string;
851
+ [DO_PROTOCOL](): DoResult<unknown>;
704
852
  _tag: string;
705
853
  }) & {
706
854
  /**
@@ -711,6 +859,16 @@ declare const Task: (<T = unknown>(params?: TaskParams) => {
711
859
  * Create a failed Task result
712
860
  */
713
861
  fail: <T>(error: unknown, data?: unknown, params?: TaskParams) => TaskFailure<T>;
862
+ /**
863
+ * Create a successful Task result (alias for success)
864
+ * Preferred for new code
865
+ */
866
+ ok: <T>(data: T, params?: TaskParams) => TaskSuccess<T>;
867
+ /**
868
+ * Create a failed Task result (alias for fail)
869
+ * Preferred for new code
870
+ */
871
+ err: <T>(error: unknown, data?: unknown, params?: TaskParams) => TaskFailure<T>;
714
872
  /**
715
873
  * Extract the error chain from a Throwable error
716
874
  * Returns an array of errors from outermost to innermost
@@ -734,7 +892,7 @@ declare const Task: (<T = unknown>(params?: TaskParams) => {
734
892
  /**
735
893
  * Convert a Promise-returning function to a Task-compatible function
736
894
  */
737
- fromPromise: <U, Args extends unknown[]>(promiseFn: (...args: Args) => Promise<U>, params?: TaskParams) => ((...args: Args) => FPromise<U>);
895
+ fromPromise: <U, Args extends unknown[]>(promiseFn: (...args: Args) => Promise<U>, params?: TaskParams) => ((...args: Args) => FPromise<TaskOutcome<U>>);
738
896
  /**
739
897
  * Convert a Task result to a Promise
740
898
  */
@@ -748,7 +906,7 @@ declare const Task: (<T = unknown>(params?: TaskParams) => {
748
906
  * @param params - Task parameters for the race operation
749
907
  * @returns A promise that resolves with the first task to complete or rejects if all tasks fail
750
908
  */
751
- race: <T>(tasks: Array<FPromise<T>>, timeoutMs?: number, params?: TaskParams) => FPromise<T>;
909
+ race: <T>(tasks: Array<FPromise<T> | FPromise<TaskOutcome<T>>>, timeoutMs?: number, params?: TaskParams) => FPromise<TaskOutcome<T>>;
752
910
  /**
753
911
  * Convert a Node.js style callback function to a Task-compatible function
754
912
  * Node.js callbacks typically have the signature (error, result) => void
@@ -757,7 +915,7 @@ declare const Task: (<T = unknown>(params?: TaskParams) => {
757
915
  * @param params - Task parameters
758
916
  * @returns A function that returns an FPromise
759
917
  */
760
- fromNodeCallback: <T, Args extends unknown[]>(nodeFn: (...args: [...Args, (error: unknown, result: T) => void]) => void, params?: TaskParams) => ((...args: Args) => FPromise<T>);
918
+ fromNodeCallback: <T, Args extends unknown[]>(nodeFn: (...args: [...Args, (error: unknown, result: T) => void]) => void, params?: TaskParams) => ((...args: Args) => FPromise<TaskOutcome<T>>);
761
919
  /**
762
920
  * Create a cancellation token source
763
921
  * @returns A cancellation token source that can be used to control task cancellation
@@ -770,8 +928,8 @@ declare const Task: (<T = unknown>(params?: TaskParams) => {
770
928
  * @param params - Task parameters
771
929
  * @returns An object with the task and a function to cancel it
772
930
  */
773
- cancellable: <T>(task: (token: CancellationToken) => Promise<T>, params?: TaskParams) => {
774
- task: FPromise<T>;
931
+ cancellable: <T>(task: (token: CancellationToken) => Promise<T> | Promise<TaskOutcome<T>>, params?: TaskParams) => {
932
+ task: FPromise<TaskOutcome<T>>;
775
933
  cancel: () => void;
776
934
  };
777
935
  /**
@@ -782,8 +940,8 @@ declare const Task: (<T = unknown>(params?: TaskParams) => {
782
940
  * @param params - Task parameters
783
941
  * @returns An object with the task, cancel function, and current progress
784
942
  */
785
- withProgress: <T>(task: (updateProgress: (percent: number) => void, token: CancellationToken) => Promise<T>, onProgress?: (percent: number) => void, params?: TaskParams) => {
786
- task: FPromise<T>;
943
+ withProgress: <T>(task: (updateProgress: (percent: number) => void, token: CancellationToken) => Promise<T> | Promise<TaskOutcome<T>>, onProgress?: (percent: number) => void, params?: TaskParams) => {
944
+ task: FPromise<TaskOutcome<T>>;
787
945
  cancel: () => void;
788
946
  currentProgress: () => number;
789
947
  };
@@ -1011,137 +1169,6 @@ declare const TypedError: (<T extends ErrorCode>(code: T, message: ErrorMessage<
1011
1169
  hasCode: <T extends ErrorCode>(error: TypedError<ErrorCode>, code: T) => error is TypedError<T>;
1012
1170
  };
1013
1171
 
1014
- /**
1015
- * LazyList provides lazy evaluation for list operations.
1016
- * Operations are deferred until the list is materialized.
1017
- *
1018
- * @example
1019
- * // Basic lazy evaluation
1020
- * const result = LazyList([1, 2, 3, 4, 5])
1021
- * .map(x => x * 2)
1022
- * .filter(x => x > 5)
1023
- * .toArray() // [6, 8, 10]
1024
- *
1025
- * @example
1026
- * // Infinite sequences with take
1027
- * const fibonacci = LazyList.iterate([0, 1], ([a, b]) => [b, a + b])
1028
- * .map(([a]) => a)
1029
- * .take(10)
1030
- * .toArray() // [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
1031
- */
1032
- interface LazyList<A extends Type> extends Foldable<A>, Pipe<LazyList<A>>, Serializable<LazyList<A>>, Typeable<"LazyList"> {
1033
- [Symbol.iterator](): Iterator<A>;
1034
- map<B extends Type>(f: (a: A) => B): LazyList<B>;
1035
- flatMap<B extends Type>(f: (a: A) => LazyList<B>): LazyList<B>;
1036
- filter(predicate: (a: A) => boolean): LazyList<A>;
1037
- take(n: number): LazyList<A>;
1038
- drop(n: number): LazyList<A>;
1039
- takeWhile(predicate: (a: A) => boolean): LazyList<A>;
1040
- dropWhile(predicate: (a: A) => boolean): LazyList<A>;
1041
- concat(other: LazyList<A>): LazyList<A>;
1042
- zip<B extends Type>(other: LazyList<B>): LazyList<[A, B]>;
1043
- toList(): List<A>;
1044
- toArray(): A[];
1045
- forEach(f: (a: A) => void): void;
1046
- reduce<B extends Type>(f: (acc: B, a: A) => B, initial: B): B;
1047
- find(predicate: (a: A) => boolean): Option<A>;
1048
- some(predicate: (a: A) => boolean): boolean;
1049
- every(predicate: (a: A) => boolean): boolean;
1050
- count(): number;
1051
- first(): Option<A>;
1052
- last(): Option<A>;
1053
- toString(): string;
1054
- }
1055
- /**
1056
- * Lazy list implementation for efficient deferred computation
1057
- * @example
1058
- * // Process large datasets efficiently
1059
- * const result = LazyList.range(1, 1000000)
1060
- * .filter(x => x % 2 === 0)
1061
- * .map(x => x * x)
1062
- * .take(5)
1063
- * .toArray() // [4, 16, 36, 64, 100]
1064
- *
1065
- * @example
1066
- * // Infinite sequences
1067
- * const primes = LazyList.iterate(2, n => n + 1)
1068
- * .filter(isPrime)
1069
- * .take(10)
1070
- * .toArray() // First 10 prime numbers
1071
- *
1072
- * @example
1073
- * // Combining operations
1074
- * const evens = LazyList.range(0, 100, 2)
1075
- * const odds = LazyList.range(1, 100, 2)
1076
- * const combined = evens.zip(odds)
1077
- * .map(([e, o]) => e + o)
1078
- * .take(5)
1079
- * .toArray() // [1, 5, 9, 13, 17]
1080
- */
1081
- declare const LazyList: (<A extends Type>(iterable: Iterable<A>) => LazyList<A>) & {
1082
- /**
1083
- * Create an empty LazyList
1084
- * @example
1085
- * const empty = LazyList.empty<number>()
1086
- * empty.toArray() // []
1087
- */
1088
- empty: <A extends Type>() => LazyList<A>;
1089
- /**
1090
- * Create a LazyList from a single value
1091
- * @example
1092
- * const single = LazyList.of(42)
1093
- * .map(x => x * 2)
1094
- * .toArray() // [84]
1095
- */
1096
- of: <A extends Type>(value: A) => LazyList<A>;
1097
- /**
1098
- * Create a LazyList from multiple values
1099
- */
1100
- from: <A extends Type>(...values: A[]) => LazyList<A>;
1101
- /**
1102
- * Create an infinite LazyList by repeatedly applying a function
1103
- * @example
1104
- * // Powers of 2
1105
- * const powers = LazyList.iterate(1, x => x * 2)
1106
- * .take(10)
1107
- * .toArray() // [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
1108
- *
1109
- * @example
1110
- * // Fibonacci sequence
1111
- * const fib = LazyList.iterate([0, 1], ([a, b]) => [b, a + b])
1112
- * .map(([a]) => a)
1113
- * .take(8)
1114
- * .toArray() // [0, 1, 1, 2, 3, 5, 8, 13]
1115
- */
1116
- iterate: <A extends Type>(initial: A, f: (a: A) => A) => LazyList<A>;
1117
- /**
1118
- * Create an infinite LazyList by repeatedly calling a function
1119
- */
1120
- generate: <A extends Type>(f: () => A) => LazyList<A>;
1121
- /**
1122
- * Create a LazyList of numbers from start to end (exclusive)
1123
- * @example
1124
- * LazyList.range(1, 6).toArray() // [1, 2, 3, 4, 5]
1125
- * LazyList.range(0, 10, 2).toArray() // [0, 2, 4, 6, 8]
1126
- * LazyList.range(10, 0, -1).toArray() // [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
1127
- *
1128
- * @example
1129
- * // Sum of squares from 1 to 100
1130
- * const sum = LazyList.range(1, 101)
1131
- * .map(x => x * x)
1132
- * .reduce((a, b) => a + b, 0) // 338350
1133
- */
1134
- range: (start: number, end: number, step?: number) => LazyList<number>;
1135
- /**
1136
- * Create a LazyList that repeats a value n times (or infinitely if n is not provided)
1137
- */
1138
- repeat: <A extends Type>(value: A, n?: number) => LazyList<A>;
1139
- /**
1140
- * Create a LazyList that cycles through an iterable infinitely
1141
- */
1142
- cycle: <A extends Type>(iterable: Iterable<A>) => LazyList<A>;
1143
- };
1144
-
1145
1172
  /**
1146
1173
  * Validation rule types using template literal types
1147
1174
  */
@@ -1299,15 +1326,14 @@ type UniversalContainer = Option<unknown> | List<unknown> | Either<unknown, unkn
1299
1326
  */
1300
1327
  declare const HKT: {
1301
1328
  (): {
1302
- _type: string;
1329
+ _tag: string;
1303
1330
  map: <F, A, B>(fa: unknown, f: (a: A) => B) => unknown;
1304
1331
  flatten: <F, A>(ffa: unknown) => unknown;
1305
1332
  flatMap: <F, A, B>(fa: unknown, f: (a: A) => unknown) => unknown;
1306
1333
  ap: <F, A, B>(ff: unknown, fa: unknown) => unknown;
1307
1334
  sequence: <F, G, A>(fga: unknown) => unknown;
1308
1335
  traverse: <F, G, A, B>(fa: unknown, f: (a: A) => unknown) => unknown;
1309
- toString(): string;
1310
- _tag: string;
1336
+ _type: string;
1311
1337
  };
1312
1338
  map<F = unknown, A = unknown, B = unknown>(fa: unknown, f: (a: A) => B): unknown;
1313
1339
  flatten<F = unknown, A = unknown>(ffa: unknown): unknown;
@@ -1779,4 +1805,4 @@ declare const Stack: (<A extends Type>(values?: A[]) => Stack<A>) & {
1779
1805
  fromBinary: <A>(binary: string) => Stack<A>;
1780
1806
  };
1781
1807
 
1782
- export { type Async, Base, BoundedNumber, BoundedString, Brand, type CancellationToken, type CancellationTokenSource, Companion, Cond, ESMap, type ESMapType, Either, type EitherKind, EmailAddress, type ErrorChainElement, type ErrorCode, type ErrorFormatterOptions, type ErrorMessage, type ErrorStatus, type ErrorWithTaskInfo, Extractable, FPromise, type FieldValidation, Foldable, FoldableUtils, type FormValidation, FunctypeBase, HKT, ISO8601Date, Identity, IntegerNumber, type Kind, Lazy, LazyList, Lazy as LazyType, List, type ListKind, Match, Matchable, NAME, NonEmptyString, NonNegativeNumber, Option, type OptionKind, ParseError, PatternString, Pipe, PositiveInteger, PositiveNumber, Ref, Ref as RefType, Serializable, Stack, type Sync, type TaggedThrowable, Task, type TaskErrorInfo, TaskFailure, type TaskMetadata, type TaskOutcome, type TaskParams, type TaskResult, TaskSuccess, Throwable, type ThrowableType, Traversable, Try, type TryKind, Type, Typeable, TypedError, type TypedErrorContext, UUID, type UniversalContainer, UrlString, ValidatedBrand, type ValidatedBrandCompanion, Validation, type ValidationRule, type Validator, Valuable, type ValuableParams, createCancellationTokenSource, createErrorSerializer, formatError, formatStackTrace, isTaggedThrowable, safeStringify };
1808
+ export { type Async, Base, BoundedNumber, BoundedString, Brand, type CancellationToken, type CancellationTokenSource, Companion, Cond, DO_PROTOCOL, DoResult, ESMap, type ESMapType, Either, type EitherKind, EmailAddress, Err, type ErrorChainElement, type ErrorCode, type ErrorFormatterOptions, type ErrorMessage, type ErrorStatus, type ErrorWithTaskInfo, Extractable, FPromise, type FieldValidation, Foldable, FoldableUtils, type FormValidation, FunctypeBase, HKT, ISO8601Date, Identity, IntegerNumber, type Kind, Lazy, LazyList, Lazy as LazyType, List, type ListKind, Match, Matchable, NAME, NonEmptyString, NonNegativeNumber, Ok, Option, type OptionKind, ParseError, PatternString, Pipe, PositiveInteger, PositiveNumber, Ref, Ref as RefType, Serializable, Stack, type Sync, type TaggedThrowable, Task, type TaskErrorInfo, TaskFailure, type TaskMetadata, type TaskOutcome, type TaskParams, type TaskResult, TaskSuccess, Throwable, type ThrowableType, Traversable, Try, type TryKind, Type, Typeable, TypedError, type TypedErrorContext, UUID, type UniversalContainer, UrlString, ValidatedBrand, type ValidatedBrandCompanion, Validation, type ValidationRule, type Validator, Valuable, type ValuableParams, createCancellationTokenSource, createErrorSerializer, formatError, formatStackTrace, isTaggedThrowable, safeStringify };
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export{G as Base,B as BoundedNumber,C as BoundedString,E as Cond,da as ESMap,q as Either,x as EmailAddress,K as FPromise,J as FPromiseCompanion,_ as FoldableUtils,$ as HKT,A as ISO8601Date,aa as Identity,u as IntegerNumber,ca as Lazy,X as LazyList,j as Left,h as List,ea as Map,F as Match,fa as MatchableUtils,H as NAME,w as NonEmptyString,t as NonNegativeNumber,b as None,d as Option,c as OptionConstructor,V as ParseError,D as PatternString,v as PositiveInteger,s as PositiveNumber,L as Ref,i as Right,e as Set,a as Some,ga as Stack,Q as Task,N as TaskFailure,O as TaskSuccess,I as Throwable,ba as Try,o as TypeCheckLeft,n as TypeCheckRight,f as Typeable,W as TypedError,z as UUID,y as UrlString,r as ValidatedBrand,Y as Validation,ha as Valuable,P as createCancellationTokenSource,U as createErrorSerializer,T as formatError,S as formatStackTrace,Z as isExtractable,l as isLeft,k as isRight,M as isTaggedThrowable,g as isTypeable,R as safeStringify,m as tryCatch,p as tryCatchAsync}from'./chunk-PPFDDUSD.mjs';export{a as Companion,b as Tuple}from'./chunk-BQJB6CCW.mjs';export{a as Brand,g as BrandedBoolean,f as BrandedNumber,e as BrandedString,d as createBrander,c as hasBrand,b as unbrand}from'./chunk-YBBRJTHY.mjs';//# sourceMappingURL=index.mjs.map
1
+ export{P as $,K as Base,F as BoundedNumber,G as BoundedString,I as Cond,a as DO_PROTOCOL,L as Do,M as DoAsync,pa as ESMap,u as Either,B as EmailAddress,S as EmptyListError,aa as Err,X as FPromise,W as FPromiseCompanion,T as FailureError,la as FoldableUtils,ma as HKT,E as ISO8601Date,na as Identity,y as IntegerNumber,oa as Lazy,h as LazyList,n as Left,R as LeftError,l as List,qa as Map,J as Match,ra as MatchableUtils,U as NAME,A as NonEmptyString,x as NonNegativeNumber,c as None,Q as NoneError,$ as Ok,e as Option,d as OptionConstructor,ha as ParseError,H as PatternString,z as PositiveInteger,w as PositiveNumber,g as Ref,m as Right,f as Set,b as Some,sa as Stack,ca as Task,Z as TaskFailure,_ as TaskSuccess,V as Throwable,i as Try,s as TypeCheckLeft,r as TypeCheckRight,j as Typeable,ia as TypedError,D as UUID,C as UrlString,v as ValidatedBrand,ja as Validation,ta as Valuable,ba as createCancellationTokenSource,ga as createErrorSerializer,fa as formatError,ea as formatStackTrace,N as isDoCapable,ka as isExtractable,p as isLeft,o as isRight,Y as isTaggedThrowable,k as isTypeable,da as safeStringify,q as tryCatch,t as tryCatchAsync,O as unwrap}from'./chunk-7VZBQDNM.mjs';export{a as Companion,b as Tuple}from'./chunk-BQJB6CCW.mjs';export{a as Brand,g as BrandedBoolean,f as BrandedNumber,e as BrandedString,d as createBrander,c as hasBrand,b as unbrand}from'./chunk-YBBRJTHY.mjs';//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1,2 +1,2 @@
1
- export { L as List } from '../Either-DgkP4DUw.js';
2
- import '../Serializable-CK9upOU0.js';
1
+ export { L as List } from '../Either-D4P39LPj.js';
2
+ import '../Typeable-CitTP1ay.js';
@@ -1,2 +1,2 @@
1
- export{h as List}from'../chunk-PPFDDUSD.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-YBBRJTHY.mjs';//# sourceMappingURL=index.mjs.map
1
+ export{l as List}from'../chunk-7VZBQDNM.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-YBBRJTHY.mjs';//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1,5 +1,5 @@
1
- import { T as Traversable, C as Collection, O as Option } from '../Either-DgkP4DUw.js';
2
- import { a as Typeable, S as Serializable, P as Pipe, F as Foldable, T as Type } from '../Serializable-CK9upOU0.js';
1
+ import { c as Traversable, C as Collection, O as Option } from '../Either-D4P39LPj.js';
2
+ import { a as Typeable, S as Serializable, P as Pipe, F as Foldable, T as Type } from '../Typeable-CitTP1ay.js';
3
3
  import { Tuple } from '../tuple/index.js';
4
4
 
5
5
  /**
@@ -1,2 +1,2 @@
1
- export{ea as Map}from'../chunk-PPFDDUSD.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-YBBRJTHY.mjs';//# sourceMappingURL=index.mjs.map
1
+ export{qa as Map}from'../chunk-7VZBQDNM.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-YBBRJTHY.mjs';//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1,2 +1,2 @@
1
- export { N as None, O as Option, m as OptionConstructor, S as Some } from '../Either-DgkP4DUw.js';
2
- import '../Serializable-CK9upOU0.js';
1
+ export { N as None, O as Option, p as OptionConstructor, S as Some } from '../Either-D4P39LPj.js';
2
+ import '../Typeable-CitTP1ay.js';
@@ -1,2 +1,2 @@
1
- export{b as None,d as Option,c as OptionConstructor,a as Some}from'../chunk-PPFDDUSD.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-YBBRJTHY.mjs';//# sourceMappingURL=index.mjs.map
1
+ export{c as None,e as Option,d as OptionConstructor,b as Some}from'../chunk-7VZBQDNM.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-YBBRJTHY.mjs';//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1,2 +1,2 @@
1
- export { n as Set } from '../Either-DgkP4DUw.js';
2
- import '../Serializable-CK9upOU0.js';
1
+ export { q as Set } from '../Either-D4P39LPj.js';
2
+ import '../Typeable-CitTP1ay.js';
@@ -1,2 +1,2 @@
1
- export{e as Set}from'../chunk-PPFDDUSD.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-YBBRJTHY.mjs';//# sourceMappingURL=index.mjs.map
1
+ export{f as Set}from'../chunk-7VZBQDNM.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-YBBRJTHY.mjs';//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1,74 +1,2 @@
1
- import { F as FunctypeBase, a as Extractable, P as Promisable, E as Either } from '../Either-DgkP4DUw.js';
2
- import { P as Pipe, T as Type } from '../Serializable-CK9upOU0.js';
3
-
4
- /**
5
- * Possible types of Try instances
6
- */
7
- type TypeNames = "Success" | "Failure";
8
- interface Try<T> extends FunctypeBase<T, TypeNames>, Extractable<T>, Pipe<T>, Promisable<T> {
9
- readonly _tag: TypeNames;
10
- readonly error: Error | undefined;
11
- isSuccess(): this is Try<T> & {
12
- readonly _tag: "Success";
13
- error: undefined;
14
- };
15
- isFailure(): this is Try<T> & {
16
- readonly _tag: "Failure";
17
- error: Error;
18
- };
19
- get: () => T;
20
- getOrElse: (defaultValue: T) => T;
21
- getOrThrow: (error?: Error) => T;
22
- orElse: (alternative: Try<T>) => Try<T>;
23
- orNull: () => T | null;
24
- orUndefined: () => T | undefined;
25
- orThrow: (error: Error) => T;
26
- toEither: () => Either<Error, T>;
27
- map: <U>(f: (value: T) => U) => Try<U>;
28
- ap: <U>(ff: Try<(value: T) => U>) => Try<U>;
29
- flatMap: <U>(f: (value: T) => Try<U>) => Try<U>;
30
- flatMapAsync: <U>(f: (value: T) => Promise<Try<U>>) => Promise<Try<U>>;
31
- /**
32
- * Pattern matches over the Try, applying onFailure if Failure and onSuccess if Success
33
- * @param onFailure - Function to apply if the Try is Failure
34
- * @param onSuccess - Function to apply if the Try is Success
35
- * @returns The result of applying the appropriate function
36
- */
37
- fold: <U extends Type>(onFailure: (error: Error) => U, onSuccess: (value: T) => U) => U;
38
- toString: () => string;
39
- /**
40
- * Pattern matches over the Try, applying a handler function based on the variant
41
- * @param patterns - Object with handler functions for Success and Failure variants
42
- * @returns The result of applying the matching handler function
43
- */
44
- match<R>(patterns: {
45
- Success: (value: T) => R;
46
- Failure: (error: Error) => R;
47
- }): R;
48
- toValue(): {
49
- _tag: TypeNames;
50
- value: T | Error;
51
- };
52
- }
53
- declare const Try: (<T>(f: () => T) => Try<T>) & {
54
- /**
55
- * Creates a Try from JSON string
56
- * @param json - The JSON string
57
- * @returns Try instance
58
- */
59
- fromJSON: <T>(json: string) => Try<T>;
60
- /**
61
- * Creates a Try from YAML string
62
- * @param yaml - The YAML string
63
- * @returns Try instance
64
- */
65
- fromYAML: <T>(yaml: string) => Try<T>;
66
- /**
67
- * Creates a Try from binary string
68
- * @param binary - The binary string
69
- * @returns Try instance
70
- */
71
- fromBinary: <T>(binary: string) => Try<T>;
72
- };
73
-
74
- export { Try, type TypeNames };
1
+ export { T as Try, r as TypeNames } from '../Either-D4P39LPj.js';
2
+ import '../Typeable-CitTP1ay.js';
@@ -1,2 +1,2 @@
1
- export{ba as Try}from'../chunk-PPFDDUSD.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-YBBRJTHY.mjs';//# sourceMappingURL=index.mjs.map
1
+ export{i as Try}from'../chunk-7VZBQDNM.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-YBBRJTHY.mjs';//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1,4 +1,4 @@
1
- import { T as Type, F as Foldable, P as Pipe, S as Serializable, a as Typeable } from '../Serializable-CK9upOU0.js';
1
+ import { T as Type, F as Foldable, P as Pipe, S as Serializable, a as Typeable } from '../Typeable-CitTP1ay.js';
2
2
 
3
3
  interface Tuple<T extends Type[]> extends Foldable<T[number]>, Pipe<Tuple<T>>, Serializable<Tuple<T>>, Typeable<"Tuple"> {
4
4
  get<K extends number>(index: K): T[K];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functype",
3
- "version": "0.11.2",
3
+ "version": "0.14.0",
4
4
  "type": "module",
5
5
  "description": "A smallish functional library for TypeScript",
6
6
  "author": "jordan.burke@gmail.com",
@@ -14,18 +14,18 @@
14
14
  "devDependencies": {
15
15
  "@eslint/compat": "^1.3.2",
16
16
  "@eslint/eslintrc": "^3.3.1",
17
- "@eslint/js": "^9.33.0",
17
+ "@eslint/js": "^9.34.0",
18
18
  "@semantic-release/commit-analyzer": "^13.0.1",
19
19
  "@semantic-release/github": "^11.0.4",
20
20
  "@semantic-release/npm": "^12.0.2",
21
21
  "@semantic-release/release-notes-generator": "^14.0.3",
22
- "@types/node": "^22.17.2",
23
- "@typescript-eslint/eslint-plugin": "^8.40.0",
24
- "@typescript-eslint/parser": "^8.40.0",
22
+ "@types/node": "^22.18.0",
23
+ "@typescript-eslint/eslint-plugin": "^8.41.0",
24
+ "@typescript-eslint/parser": "^8.41.0",
25
25
  "@vitest/coverage-v8": "^3.2.4",
26
26
  "@vitest/ui": "^3.2.4",
27
27
  "cross-env": "^10.0.0",
28
- "eslint": "^9.33.0",
28
+ "eslint": "^9.34.0",
29
29
  "eslint-config-functype": "1.3.0",
30
30
  "eslint-config-prettier": "^10.1.8",
31
31
  "eslint-plugin-functional": "^9.0.2",
@@ -38,7 +38,7 @@
38
38
  "semantic-release": "^24.2.7",
39
39
  "ts-node": "^10.9.2",
40
40
  "tsup": "^8.5.0",
41
- "typedoc": "^0.28.10",
41
+ "typedoc": "^0.28.11",
42
42
  "typescript": "5.9.2",
43
43
  "vitest": "^3.2.4"
44
44
  },
@@ -81,6 +81,12 @@
81
81
  "default": "./dist/conditional/index.mjs"
82
82
  }
83
83
  },
84
+ "./do": {
85
+ "import": {
86
+ "types": "./dist/do/index.d.ts",
87
+ "default": "./dist/do/index.mjs"
88
+ }
89
+ },
84
90
  "./lazy": {
85
91
  "import": {
86
92
  "types": "./dist/lazy/index.d.ts",