functype 0.12.0 → 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.
@@ -0,0 +1,240 @@
1
+ import { O as Option, E as Either, L as List, T as Try, y as Reshapeable, d as DoProtocol } from '../Either-D4P39LPj.js';
2
+ export { D as DO_PROTOCOL, a as DoResult } from '../Either-D4P39LPj.js';
3
+ import '../Typeable-CitTP1ay.js';
4
+
5
+ /**
6
+ * Generator-based Do-notation for monadic comprehensions
7
+ * Provides Scala-like for-comprehension syntax using JavaScript generators
8
+ *
9
+ * ## Scala Equivalents
10
+ *
11
+ * Functype: `const x = yield* $(Option(5))`
12
+ * Scala: `x <- Some(5)`
13
+ *
14
+ * Functype: `return x + y`
15
+ * Scala: `yield x + y`
16
+ *
17
+ * ## Core Concepts
18
+ *
19
+ * - **Generators**: Use `yield* $(monad)` to extract values from monads
20
+ * - **Short-circuiting**: None/Left/Failure automatically propagates
21
+ * - **Type inference**: The $ helper provides proper TypeScript types
22
+ * - **First monad wins**: Return type matches the first yielded monad
23
+ * - **Cartesian products**: Multiple List yields create all combinations
24
+ *
25
+ * ## Usage Rules
26
+ *
27
+ * 1. All yielded values MUST be monadic (Option, Either, List, Try)
28
+ * 2. Use the $ helper for type inference: `yield* $(Option(value))`
29
+ * 3. Raw values should be assigned directly without yielding
30
+ * 4. Mixed monad types are supported via Reshapeable interface
31
+ *
32
+ * @example
33
+ * // Basic Option chaining (Scala: for { x <- Some(5); y <- Some(10) } yield x + y)
34
+ * const result = Do(function* () {
35
+ * const x = yield* $(Option(5)) // Extract from Option
36
+ * const y = yield* $(Option(10)) // Extract from another Option
37
+ * return x + y // Return final value
38
+ * })
39
+ * // result: Option<number> with value 15
40
+ *
41
+ * @example
42
+ * // List comprehension (Scala: for { x <- List(1,2); y <- List(10,20) } yield (x,y))
43
+ * const pairs = Do(function* () {
44
+ * const x = yield* $(List([1, 2])) // Iterates: 1, 2
45
+ * const y = yield* $(List([10, 20])) // Iterates: 10, 20
46
+ * return { x, y } // All combinations
47
+ * })
48
+ * // pairs: List([{x:1,y:10}, {x:1,y:20}, {x:2,y:10}, {x:2,y:20}])
49
+ *
50
+ * @example
51
+ * // Error propagation with Either
52
+ * const validate = Do(function* () {
53
+ * const email = yield* $(validateEmail(input)) // Either<string, Email>
54
+ * const user = yield* $(fetchUser(email)) // Either<string, User>
55
+ * const saved = yield* $(saveUser(user)) // Either<string, Result>
56
+ * return saved
57
+ * })
58
+ * // If any step returns Left, entire chain short-circuits with that error
59
+ *
60
+ * @see {@link https://github.com/jordanburke/functype/blob/main/docs/do-notation.md} Full documentation
61
+ * @module Do
62
+ */
63
+
64
+ type OptionLike = {
65
+ _tag: "Some" | "None";
66
+ isSome(): boolean;
67
+ get(): unknown;
68
+ };
69
+ type EitherLike = {
70
+ _tag: "Left" | "Right";
71
+ isLeft(): boolean;
72
+ isRight(): boolean;
73
+ value: unknown;
74
+ };
75
+ type ListLike = {
76
+ _tag: "List";
77
+ toArray(): unknown[];
78
+ };
79
+ type TryLike = {
80
+ _tag: "Success" | "Failure";
81
+ isSuccess(): boolean;
82
+ get(): unknown;
83
+ };
84
+ /**
85
+ * Executes a generator-based monadic comprehension
86
+ * Returns the same monad type as the first yielded monad (Scala semantics)
87
+ *
88
+ * - Option comprehensions return Option (None on short-circuit)
89
+ * - Either comprehensions return Either (Left with error on short-circuit)
90
+ * - List comprehensions return List (empty or cartesian product)
91
+ * - Try comprehensions return Try (Failure with error on short-circuit)
92
+ *
93
+ * Type Inference Notes:
94
+ * - TypeScript infers the correct return type for homogeneous comprehensions
95
+ * - For mixed monad types, TypeScript returns a union type
96
+ * - Use DoTyped<T> or type assertions for mixed scenarios
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * // Option comprehension returns Option:
101
+ * const result = Do(function* () {
102
+ * const x = yield* $(Option(5));
103
+ * const y = yield* $(Option(10));
104
+ * return x + y;
105
+ * });
106
+ * // result: Option(15)
107
+ *
108
+ * // Either comprehension returns Either:
109
+ * const result = Do(function* () {
110
+ * const x = yield* $(Right(5));
111
+ * const y = yield* $(Left("error"));
112
+ * return x + y;
113
+ * });
114
+ * // result: Left("error") - error is preserved
115
+ *
116
+ * // List comprehension returns List with cartesian product:
117
+ * const result = Do(function* () {
118
+ * const x = yield* $(List([1, 2]));
119
+ * const y = yield* $(List([3, 4]));
120
+ * return x + y;
121
+ * });
122
+ * // result: List([4, 5, 5, 6])
123
+ *
124
+ * // Mixed types - use type assertion or DoTyped:
125
+ * const result = Do(function* () {
126
+ * const x = yield* $(Option(5));
127
+ * const y = yield* $(Right<string, number>(10));
128
+ * return x + y;
129
+ * }) as Option<number>;
130
+ * // result: Option(15)
131
+ * ```
132
+ *
133
+ * @param gen - Generator function that yields monads and returns a result
134
+ * @returns The same monad type as the first yield
135
+ */
136
+ declare function Do<T>(gen: () => Generator<OptionLike, T, unknown>): Option<T>;
137
+ declare function Do<L, R>(gen: () => Generator<EitherLike, R, unknown>): Either<L, R>;
138
+ declare function Do<T>(gen: () => Generator<ListLike, T, unknown>): List<T>;
139
+ declare function Do<T>(gen: () => Generator<TryLike, T, unknown>): Try<T>;
140
+ declare function Do<T>(gen: () => Generator<OptionLike | EitherLike | ListLike | TryLike, T, unknown>): Reshapeable<T>;
141
+ declare function Do<T>(gen: () => Generator<unknown, T, unknown>): unknown;
142
+ /**
143
+ * Executes an async generator-based monadic comprehension
144
+ * Returns the same monad type as the first yielded monad
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * const result = await DoAsync(async function* () {
149
+ * const user = yield* $(await fetchUser(id)); // Promise<Option<User>> → User
150
+ * const profile = yield* $(await getProfile(user)); // Promise<Either<Error, Profile>> → Profile
151
+ * return { user, profile };
152
+ * });
153
+ * // result type matches first yield
154
+ * ```
155
+ *
156
+ * @param gen - Async generator function that yields monads/promises and returns a result
157
+ * @returns Promise of the same monad type as first yield
158
+ */
159
+ declare function DoAsync<T>(gen: () => AsyncGenerator<OptionLike, T, unknown>): Promise<Option<T>>;
160
+ declare function DoAsync<L, R>(gen: () => AsyncGenerator<EitherLike, R, unknown>): Promise<Either<L, R>>;
161
+ declare function DoAsync<T>(gen: () => AsyncGenerator<ListLike, T, unknown>): Promise<List<T>>;
162
+ declare function DoAsync<T>(gen: () => AsyncGenerator<TryLike, T, unknown>): Promise<Try<T>>;
163
+ declare function DoAsync<T>(gen: () => AsyncGenerator<OptionLike | EitherLike | ListLike | TryLike, T, unknown>): Promise<Reshapeable<T>>;
164
+ declare function DoAsync<T>(gen: () => AsyncGenerator<unknown, T, unknown>): Promise<unknown>;
165
+ /**
166
+ * Helper function to check if a value implements the Do protocol
167
+ * @param value - Value to check
168
+ * @returns True if the value implements DoProtocol
169
+ */
170
+ declare function isDoCapable<T>(value: unknown): value is DoProtocol<T>;
171
+ /**
172
+ * Manually unwrap a monad using the Do protocol
173
+ * Useful for testing or when you need to unwrap outside of a Do-comprehension
174
+ *
175
+ * @param monad - Monad to unwrap
176
+ * @returns The unwrapped value
177
+ * @throws Error if the monad cannot be unwrapped
178
+ */
179
+ declare function unwrap<T>(monad: DoProtocol<T>): T;
180
+ /**
181
+ * Type helper for Do-notation generators.
182
+ * Provides better type hints in IDEs.
183
+ *
184
+ * @example
185
+ * ```typescript
186
+ * const result = Do(function* (): DoGenerator<number> {
187
+ * const x = yield* $(List([1, 2])) // x is still unknown but return type is clear
188
+ * const y = yield* $(List([3, 4]))
189
+ * return x + y
190
+ * })
191
+ * ```
192
+ */
193
+ type DoGenerator<T, TYield = unknown> = Generator<TYield, T, unknown>;
194
+ /**
195
+ * Extracts values from monads in Do-notation with type inference.
196
+ * The '$' symbol is the universal extraction operator in functional programming.
197
+ *
198
+ * @example
199
+ * ```typescript
200
+ * const result = Do(function* () {
201
+ * const x = yield* $(Option(5)) // x: number
202
+ * const y = yield* $(List([1, 2, 3])) // y: number (for cartesian product)
203
+ * const name = yield* $(Right("Alice")) // name: string
204
+ * return `${name}: ${x + y}`
205
+ * })
206
+ * ```
207
+ *
208
+ * @param monad - Any monad that can be unwrapped (Option, Either, List, Try, etc.)
209
+ * @returns A generator that yields the monad and returns its extracted value
210
+ */
211
+ declare function $<T>(monad: Option<T>): Generator<Option<T>, T, T>;
212
+ declare function $<L, R>(monad: Either<L, R>): Generator<Either<L, R>, R, R>;
213
+ declare function $<T>(monad: List<T>): Generator<List<T>, T, T>;
214
+ declare function $<T>(monad: Try<T>): Generator<Try<T>, T, T>;
215
+ declare function $<T>(monad: DoProtocol<T>): Generator<DoProtocol<T>, T, T>;
216
+ declare function $<M>(monad: M): Generator<M, InferYieldType<M>, InferYieldType<M>>;
217
+ type InferYieldType<M> = M extends {
218
+ isSome(): boolean;
219
+ get(): infer T;
220
+ } ? T : M extends {
221
+ isRight(): boolean;
222
+ value: infer R;
223
+ } ? R : M extends {
224
+ toArray(): (infer T)[];
225
+ } ? T : M extends {
226
+ isSuccess(): boolean;
227
+ get(): infer T;
228
+ } ? T : M extends DoProtocol<infer T> ? T : unknown;
229
+ declare const NoneError: (message?: string) => Error;
230
+ interface LeftErrorType<L> extends Error {
231
+ value: L;
232
+ }
233
+ declare const LeftError: <L>(value: L, message?: string) => LeftErrorType<L>;
234
+ declare const EmptyListError: (message?: string) => Error;
235
+ interface FailureErrorType extends Error {
236
+ cause: Error;
237
+ }
238
+ declare const FailureError: (cause: Error, message?: string) => FailureErrorType;
239
+
240
+ export { $, Do, DoAsync, type DoGenerator, DoProtocol, EmptyListError, FailureError, type FailureErrorType, LeftError, type LeftErrorType, NoneError, isDoCapable, unwrap };
@@ -0,0 +1,2 @@
1
+ export{P as $,a as DO_PROTOCOL,L as Do,M as DoAsync,S as EmptyListError,T as FailureError,R as LeftError,Q as NoneError,N as isDoCapable,O as unwrap}from'../chunk-7VZBQDNM.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-YBBRJTHY.mjs';//# sourceMappingURL=index.mjs.map
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.mjs"}
@@ -1,2 +1,2 @@
1
- export { E as Either, c as Left, R as Right, b as TestEither, f as TypeCheckLeft, e as TypeCheckRight, d as isLeft, i as isRight, t as tryCatch, g as tryCatchAsync } from '../Either-DgkP4DUw.js';
2
- import '../Serializable-CK9upOU0.js';
1
+ export { E as Either, f as Left, R as Right, e as TestEither, j as TypeCheckLeft, h as TypeCheckRight, g as isLeft, i as isRight, t as tryCatch, k as tryCatchAsync } from '../Either-D4P39LPj.js';
2
+ import '../Typeable-CitTP1ay.js';
@@ -1,2 +1,2 @@
1
- export{q as Either,j as Left,i as Right,o as TypeCheckLeft,n as TypeCheckRight,l as isLeft,k as isRight,m as tryCatch,p as tryCatchAsync}from'../chunk-VXULTLLY.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-YBBRJTHY.mjs';//# sourceMappingURL=index.mjs.map
1
+ export{u as Either,n as Left,m as Right,s as TypeCheckLeft,r as TypeCheckRight,p as isLeft,o as isRight,q as tryCatch,t as tryCatchAsync}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 { E as Either } from '../Either-DgkP4DUw.js';
2
- import { T as Type } from '../Serializable-CK9upOU0.js';
1
+ import { E as Either } from '../Either-D4P39LPj.js';
2
+ import { T as Type } from '../Typeable-CitTP1ay.js';
3
3
 
4
4
  /**
5
5
  * Error context information that provides additional metadata about errors.
@@ -1,2 +1,2 @@
1
- export{K as FPromise,J as FPromiseCompanion}from'../chunk-VXULTLLY.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-YBBRJTHY.mjs';//# sourceMappingURL=index.mjs.map
1
+ export{X as FPromise,W as FPromiseCompanion}from'../chunk-7VZBQDNM.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-YBBRJTHY.mjs';//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
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
 
@@ -716,6 +848,7 @@ declare const Task: (<T = unknown>(params?: TaskParams) => {
716
848
  */
717
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>>;
718
850
  toString(): string;
851
+ [DO_PROTOCOL](): DoResult<unknown>;
719
852
  _tag: string;
720
853
  }) & {
721
854
  /**
@@ -1036,137 +1169,6 @@ declare const TypedError: (<T extends ErrorCode>(code: T, message: ErrorMessage<
1036
1169
  hasCode: <T extends ErrorCode>(error: TypedError<ErrorCode>, code: T) => error is TypedError<T>;
1037
1170
  };
1038
1171
 
1039
- /**
1040
- * LazyList provides lazy evaluation for list operations.
1041
- * Operations are deferred until the list is materialized.
1042
- *
1043
- * @example
1044
- * // Basic lazy evaluation
1045
- * const result = LazyList([1, 2, 3, 4, 5])
1046
- * .map(x => x * 2)
1047
- * .filter(x => x > 5)
1048
- * .toArray() // [6, 8, 10]
1049
- *
1050
- * @example
1051
- * // Infinite sequences with take
1052
- * const fibonacci = LazyList.iterate([0, 1], ([a, b]) => [b, a + b])
1053
- * .map(([a]) => a)
1054
- * .take(10)
1055
- * .toArray() // [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
1056
- */
1057
- interface LazyList<A extends Type> extends Foldable<A>, Pipe<LazyList<A>>, Serializable<LazyList<A>>, Typeable<"LazyList"> {
1058
- [Symbol.iterator](): Iterator<A>;
1059
- map<B extends Type>(f: (a: A) => B): LazyList<B>;
1060
- flatMap<B extends Type>(f: (a: A) => LazyList<B>): LazyList<B>;
1061
- filter(predicate: (a: A) => boolean): LazyList<A>;
1062
- take(n: number): LazyList<A>;
1063
- drop(n: number): LazyList<A>;
1064
- takeWhile(predicate: (a: A) => boolean): LazyList<A>;
1065
- dropWhile(predicate: (a: A) => boolean): LazyList<A>;
1066
- concat(other: LazyList<A>): LazyList<A>;
1067
- zip<B extends Type>(other: LazyList<B>): LazyList<[A, B]>;
1068
- toList(): List<A>;
1069
- toArray(): A[];
1070
- forEach(f: (a: A) => void): void;
1071
- reduce<B extends Type>(f: (acc: B, a: A) => B, initial: B): B;
1072
- find(predicate: (a: A) => boolean): Option<A>;
1073
- some(predicate: (a: A) => boolean): boolean;
1074
- every(predicate: (a: A) => boolean): boolean;
1075
- count(): number;
1076
- first(): Option<A>;
1077
- last(): Option<A>;
1078
- toString(): string;
1079
- }
1080
- /**
1081
- * Lazy list implementation for efficient deferred computation
1082
- * @example
1083
- * // Process large datasets efficiently
1084
- * const result = LazyList.range(1, 1000000)
1085
- * .filter(x => x % 2 === 0)
1086
- * .map(x => x * x)
1087
- * .take(5)
1088
- * .toArray() // [4, 16, 36, 64, 100]
1089
- *
1090
- * @example
1091
- * // Infinite sequences
1092
- * const primes = LazyList.iterate(2, n => n + 1)
1093
- * .filter(isPrime)
1094
- * .take(10)
1095
- * .toArray() // First 10 prime numbers
1096
- *
1097
- * @example
1098
- * // Combining operations
1099
- * const evens = LazyList.range(0, 100, 2)
1100
- * const odds = LazyList.range(1, 100, 2)
1101
- * const combined = evens.zip(odds)
1102
- * .map(([e, o]) => e + o)
1103
- * .take(5)
1104
- * .toArray() // [1, 5, 9, 13, 17]
1105
- */
1106
- declare const LazyList: (<A extends Type>(iterable: Iterable<A>) => LazyList<A>) & {
1107
- /**
1108
- * Create an empty LazyList
1109
- * @example
1110
- * const empty = LazyList.empty<number>()
1111
- * empty.toArray() // []
1112
- */
1113
- empty: <A extends Type>() => LazyList<A>;
1114
- /**
1115
- * Create a LazyList from a single value
1116
- * @example
1117
- * const single = LazyList.of(42)
1118
- * .map(x => x * 2)
1119
- * .toArray() // [84]
1120
- */
1121
- of: <A extends Type>(value: A) => LazyList<A>;
1122
- /**
1123
- * Create a LazyList from multiple values
1124
- */
1125
- from: <A extends Type>(...values: A[]) => LazyList<A>;
1126
- /**
1127
- * Create an infinite LazyList by repeatedly applying a function
1128
- * @example
1129
- * // Powers of 2
1130
- * const powers = LazyList.iterate(1, x => x * 2)
1131
- * .take(10)
1132
- * .toArray() // [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
1133
- *
1134
- * @example
1135
- * // Fibonacci sequence
1136
- * const fib = LazyList.iterate([0, 1], ([a, b]) => [b, a + b])
1137
- * .map(([a]) => a)
1138
- * .take(8)
1139
- * .toArray() // [0, 1, 1, 2, 3, 5, 8, 13]
1140
- */
1141
- iterate: <A extends Type>(initial: A, f: (a: A) => A) => LazyList<A>;
1142
- /**
1143
- * Create an infinite LazyList by repeatedly calling a function
1144
- */
1145
- generate: <A extends Type>(f: () => A) => LazyList<A>;
1146
- /**
1147
- * Create a LazyList of numbers from start to end (exclusive)
1148
- * @example
1149
- * LazyList.range(1, 6).toArray() // [1, 2, 3, 4, 5]
1150
- * LazyList.range(0, 10, 2).toArray() // [0, 2, 4, 6, 8]
1151
- * LazyList.range(10, 0, -1).toArray() // [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
1152
- *
1153
- * @example
1154
- * // Sum of squares from 1 to 100
1155
- * const sum = LazyList.range(1, 101)
1156
- * .map(x => x * x)
1157
- * .reduce((a, b) => a + b, 0) // 338350
1158
- */
1159
- range: (start: number, end: number, step?: number) => LazyList<number>;
1160
- /**
1161
- * Create a LazyList that repeats a value n times (or infinitely if n is not provided)
1162
- */
1163
- repeat: <A extends Type>(value: A, n?: number) => LazyList<A>;
1164
- /**
1165
- * Create a LazyList that cycles through an iterable infinitely
1166
- */
1167
- cycle: <A extends Type>(iterable: Iterable<A>) => LazyList<A>;
1168
- };
1169
-
1170
1172
  /**
1171
1173
  * Validation rule types using template literal types
1172
1174
  */
@@ -1324,15 +1326,14 @@ type UniversalContainer = Option<unknown> | List<unknown> | Either<unknown, unkn
1324
1326
  */
1325
1327
  declare const HKT: {
1326
1328
  (): {
1327
- _type: string;
1329
+ _tag: string;
1328
1330
  map: <F, A, B>(fa: unknown, f: (a: A) => B) => unknown;
1329
1331
  flatten: <F, A>(ffa: unknown) => unknown;
1330
1332
  flatMap: <F, A, B>(fa: unknown, f: (a: A) => unknown) => unknown;
1331
1333
  ap: <F, A, B>(ff: unknown, fa: unknown) => unknown;
1332
1334
  sequence: <F, G, A>(fga: unknown) => unknown;
1333
1335
  traverse: <F, G, A, B>(fa: unknown, f: (a: A) => unknown) => unknown;
1334
- toString(): string;
1335
- _tag: string;
1336
+ _type: string;
1336
1337
  };
1337
1338
  map<F = unknown, A = unknown, B = unknown>(fa: unknown, f: (a: A) => B): unknown;
1338
1339
  flatten<F = unknown, A = unknown>(ffa: unknown): unknown;
@@ -1804,4 +1805,4 @@ declare const Stack: (<A extends Type>(values?: A[]) => Stack<A>) & {
1804
1805
  fromBinary: <A>(binary: string) => Stack<A>;
1805
1806
  };
1806
1807
 
1807
- export { type Async, Base, BoundedNumber, BoundedString, Brand, type CancellationToken, type CancellationTokenSource, Companion, Cond, 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 };
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,fa as ESMap,q as Either,x as EmailAddress,Q as Err,K as FPromise,J as FPromiseCompanion,aa as FoldableUtils,ba as HKT,A as ISO8601Date,ca as Identity,u as IntegerNumber,ea as Lazy,Z as LazyList,j as Left,h as List,ga as Map,F as Match,ha as MatchableUtils,H as NAME,w as NonEmptyString,t as NonNegativeNumber,b as None,P as Ok,d as Option,c as OptionConstructor,X as ParseError,D as PatternString,v as PositiveInteger,s as PositiveNumber,L as Ref,i as Right,e as Set,a as Some,ia as Stack,S as Task,N as TaskFailure,O as TaskSuccess,I as Throwable,da as Try,o as TypeCheckLeft,n as TypeCheckRight,f as Typeable,Y as TypedError,z as UUID,y as UrlString,r as ValidatedBrand,_ as Validation,ja as Valuable,R as createCancellationTokenSource,W as createErrorSerializer,V as formatError,U as formatStackTrace,$ as isExtractable,l as isLeft,k as isRight,M as isTaggedThrowable,g as isTypeable,T as safeStringify,m as tryCatch,p as tryCatchAsync}from'./chunk-VXULTLLY.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-VXULTLLY.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{ga as Map}from'../chunk-VXULTLLY.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-VXULTLLY.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