functype 1.27.1 → 2.0.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.
Files changed (181) hide show
  1. package/README.md +63 -88
  2. package/dist/_virtual/_rolldown/runtime.js +1 -0
  3. package/dist/branded/ValidatedBrand.d.ts +122 -0
  4. package/dist/branded/ValidatedBrand.js +1 -0
  5. package/dist/branded/index.d.ts +52 -2
  6. package/dist/cli/data.d.ts +37 -0
  7. package/dist/cli/data.js +1 -0
  8. package/dist/cli/exports.d.ts +5 -46
  9. package/dist/cli/exports.js +1 -1
  10. package/dist/cli/formatters.js +4 -0
  11. package/dist/cli/full-interfaces.d.ts +6 -0
  12. package/dist/cli/full-interfaces.js +1139 -0
  13. package/dist/cli/index.js +3 -6
  14. package/dist/cli/interfaces.generated.js +1 -0
  15. package/dist/collections/index.d.ts +13 -0
  16. package/dist/companion/Companion.d.ts +23 -0
  17. package/dist/companion/Companion.js +1 -0
  18. package/dist/companion/CompanionTypes.d.ts +30 -0
  19. package/dist/{CompanionTypes-BVqO7Kc2.js → companion/CompanionTypes.js} +1 -1
  20. package/dist/companion/index.d.ts +2 -1
  21. package/dist/companion/index.js +1 -1
  22. package/dist/conditional/Cond.d.ts +147 -0
  23. package/dist/conditional/Cond.js +1 -0
  24. package/dist/conditional/Match.d.ts +295 -0
  25. package/dist/conditional/Match.js +1 -0
  26. package/dist/conditional/index.d.ts +3 -2
  27. package/dist/conditional/index.js +1 -1
  28. package/dist/core/base/Base.d.ts +12 -0
  29. package/dist/core/base/Base.js +1 -0
  30. package/dist/core/throwable/Throwable.d.ts +38 -0
  31. package/dist/core/throwable/Throwable.js +1 -0
  32. package/dist/decoder/Decoder.d.ts +15 -0
  33. package/dist/decoder/DecoderCompanion.js +1 -0
  34. package/dist/decoder/DecoderError.d.ts +56 -0
  35. package/dist/decoder/DecoderError.js +2 -0
  36. package/dist/decoder/Encoder.d.ts +15 -0
  37. package/dist/decoder/index.d.ts +71 -2
  38. package/dist/decoder/index.js +1 -1
  39. package/dist/decoder/tagged.js +1 -0
  40. package/dist/do/index.d.ts +246 -2
  41. package/dist/do/index.js +1 -1
  42. package/dist/do/protocol.d.ts +29 -0
  43. package/dist/either/index.d.ts +279 -2
  44. package/dist/either/index.js +1 -1
  45. package/dist/error/ErrorChain.d.ts +60 -0
  46. package/dist/error/ErrorChain.js +4 -0
  47. package/dist/error/ErrorFormatter.d.ts +67 -0
  48. package/dist/error/ErrorFormatter.js +6 -0
  49. package/dist/error/ParseError.d.ts +6 -0
  50. package/dist/error/ParseError.js +1 -0
  51. package/dist/error/typed/TypedError.d.ts +146 -0
  52. package/dist/error/typed/TypedError.js +1 -0
  53. package/dist/error/typed/Validation.d.ts +76 -0
  54. package/dist/error/typed/Validation.js +1 -0
  55. package/dist/extractable/Extractable.d.ts +62 -0
  56. package/dist/extractable/Extractable.js +1 -0
  57. package/dist/fetch/Http.d.ts +32 -0
  58. package/dist/fetch/Http.js +1 -0
  59. package/dist/fetch/HttpClient.d.ts +80 -0
  60. package/dist/fetch/HttpClient.js +1 -0
  61. package/dist/fetch/HttpError.d.ts +57 -0
  62. package/dist/fetch/HttpError.js +1 -0
  63. package/dist/fetch/HttpRequest.d.ts +103 -0
  64. package/dist/fetch/index.d.ts +5 -2
  65. package/dist/fetch/index.js +1 -1
  66. package/dist/foldable/Foldable.d.ts +27 -0
  67. package/dist/foldable/index.d.ts +55 -0
  68. package/dist/foldable/index.js +1 -0
  69. package/dist/functype/Functype.d.ts +76 -0
  70. package/dist/functype/FunctypeSum.d.ts +39 -0
  71. package/dist/functype/index.d.ts +4 -2
  72. package/dist/hkt/index.d.ts +68 -0
  73. package/dist/hkt/index.js +1 -0
  74. package/dist/identity/Identity.d.ts +34 -0
  75. package/dist/identity/Identity.js +1 -0
  76. package/dist/index.d.ts +74 -8
  77. package/dist/index.js +1 -1
  78. package/dist/internal/base64.js +1 -0
  79. package/dist/internal/call-alone.js +1 -0
  80. package/dist/internal/concurrency.d.ts +11 -0
  81. package/dist/internal/concurrency.js +1 -0
  82. package/dist/internal/define.js +1 -0
  83. package/dist/internal/mutation-utils.js +1 -0
  84. package/dist/internal/signal.js +1 -0
  85. package/dist/internal/stringify.js +1 -0
  86. package/dist/invariant/index.d.ts +32 -2
  87. package/dist/io/Context.d.ts +112 -0
  88. package/dist/io/Context.js +1 -0
  89. package/dist/io/Exit.d.ts +249 -0
  90. package/dist/io/Exit.js +1 -0
  91. package/dist/io/IO.d.ts +1243 -0
  92. package/dist/io/IO.js +1 -0
  93. package/dist/io/Layer.d.ts +139 -0
  94. package/dist/io/Layer.js +1 -0
  95. package/dist/io/SpanTracer.d.ts +78 -0
  96. package/dist/io/SpanTracer.js +1 -0
  97. package/dist/io/Tag.d.ts +75 -0
  98. package/dist/io/Tag.js +1 -0
  99. package/dist/io/TestClock.d.ts +133 -0
  100. package/dist/io/TestClock.js +1 -0
  101. package/dist/io/index.d.ts +41 -2
  102. package/dist/io/index.js +1 -1
  103. package/dist/lazy/Lazy.d.ts +312 -0
  104. package/dist/lazy/Lazy.js +1 -0
  105. package/dist/lazy/index.d.ts +2 -2
  106. package/dist/lazy/index.js +1 -1
  107. package/dist/list/LazyList.d.ts +182 -0
  108. package/dist/list/LazyList.js +1 -0
  109. package/dist/list/index.d.ts +137 -2
  110. package/dist/list/index.js +1 -1
  111. package/dist/logger/index.d.ts +24 -2
  112. package/dist/map/index.d.ts +95 -2
  113. package/dist/map/index.js +1 -1
  114. package/dist/map/shim.d.ts +13 -0
  115. package/dist/map/shim.js +1 -0
  116. package/dist/matchable/Matchable.d.ts +38 -0
  117. package/dist/matchable/Matchable.js +1 -0
  118. package/dist/obj/Obj.d.ts +212 -0
  119. package/dist/obj/Obj.js +1 -0
  120. package/dist/obj/index.d.ts +2 -2
  121. package/dist/obj/index.js +1 -1
  122. package/dist/option/index.d.ts +304 -2
  123. package/dist/option/index.js +1 -1
  124. package/dist/package.json.js +1 -0
  125. package/dist/pipe/index.d.ts +14 -0
  126. package/dist/ref/Ref.d.ts +77 -0
  127. package/dist/ref/Ref.js +1 -0
  128. package/dist/reshapeable/Reshapeable.d.ts +90 -0
  129. package/dist/serializable/Serializable.d.ts +39 -0
  130. package/dist/serialization/Serialization.d.ts +147 -0
  131. package/dist/serialization/Serialization.js +1 -0
  132. package/dist/serialization/SerializationCompanion.d.ts +125 -0
  133. package/dist/serialization/SerializationCompanion.js +1 -0
  134. package/dist/serialization/error-envelope.d.ts +44 -0
  135. package/dist/serialization/error-envelope.js +1 -0
  136. package/dist/serialization/index.d.ts +4 -2
  137. package/dist/serialization/index.js +1 -1
  138. package/dist/set/index.d.ts +106 -2
  139. package/dist/set/index.js +1 -1
  140. package/dist/stack/Stack.d.ts +120 -0
  141. package/dist/stack/Stack.js +1 -0
  142. package/dist/traced/TraceEvent.d.ts +27 -0
  143. package/dist/traced/TracedOption.d.ts +46 -0
  144. package/dist/traced/TracedOption.js +1 -0
  145. package/dist/traced/Tracer.d.ts +26 -0
  146. package/dist/traversable/KVTraversable.d.ts +14 -0
  147. package/dist/traversable/Traversable.d.ts +30 -0
  148. package/dist/try/index.d.ts +238 -2
  149. package/dist/try/index.js +1 -1
  150. package/dist/tuple/index.d.ts +92 -2
  151. package/dist/tuple/index.js +1 -1
  152. package/dist/typeable/Typeable.d.ts +40 -0
  153. package/dist/typeable/Typeable.js +1 -0
  154. package/dist/typeclass/ContainerOps.d.ts +131 -0
  155. package/dist/typeclass/Functor.d.ts +41 -0
  156. package/dist/typeclass/Promisable.d.ts +33 -0
  157. package/dist/typeclass/index.d.ts +4 -1
  158. package/dist/typeclass/index.js +1 -1
  159. package/dist/typeclass/variance.d.ts +54 -0
  160. package/dist/typeclass/variance.js +1 -0
  161. package/dist/types/index.d.ts +1 -0
  162. package/dist/util/index.d.ts +1 -3
  163. package/dist/valuable/Valuable.d.ts +28 -0
  164. package/dist/valuable/Valuable.js +1 -0
  165. package/dist/wire/index.d.ts +40 -2
  166. package/package.json +7 -12
  167. package/dist/Brand-bfnGXuum.d.ts +0 -54
  168. package/dist/Companion-DiOMBHDG.js +0 -1
  169. package/dist/CompanionTypes-Cc90cQ4P.d.ts +0 -58
  170. package/dist/Invariant-DEan-SxV.d.ts +0 -35
  171. package/dist/Logger-BmprRS8v.d.ts +0 -27
  172. package/dist/Tuple-B8KM-H8Y.d.ts +0 -213
  173. package/dist/Wire-3hvw0Ogg.d.ts +0 -42
  174. package/dist/core/task/index.d.ts +0 -2
  175. package/dist/core/task/index.js +0 -1
  176. package/dist/full-interfaces-0XJEOHi_.js +0 -1202
  177. package/dist/index-CLYh2qZu.d.ts +0 -6649
  178. package/dist/rolldown-runtime-DK3Fl9T5.js +0 -1
  179. package/dist/serialization-9_SyrfdG.js +0 -3
  180. package/dist/src-BTLBc-KK.js +0 -10
  181. package/dist/typeclass-C61yDVYd.js +0 -1
@@ -0,0 +1,1139 @@
1
+ const e={Option:`export type Option<T extends Type> = SomeOf<T> | NoneOf<T>
2
+
3
+ export interface OptionBase<out T extends Type>
4
+ extends Functype<T, "Some" | "None">, Promisable<T>, Doable<T>, Reshapeable<T> {
5
+ /** The contained value (undefined for None) */
6
+ readonly value: T | undefined
7
+ /** Whether this Option contains no value */
8
+ readonly isEmpty: boolean
9
+ /**
10
+ * Returns true if this Option is a Some (contains a value)
11
+ * @returns true if this Option contains a value, false otherwise
12
+ */
13
+ isSome(): this is SomeOf<T>
14
+ /**
15
+ * Returns true if this Option is a None (contains no value)
16
+ * @returns true if this Option is empty, false otherwise
17
+ */
18
+ isNone(): this is NoneOf<T>
19
+ /**
20
+ * Returns the contained value, or calls \`defaultValue\` if None. The default is lazy: it runs
21
+ * only on None. The default is typed against \`T\` first, so \`() => "light"\` on an
22
+ * \`Option<"light" | "dark">\` stays \`"light" | "dark"\`. A default of another type widens the
23
+ * result to \`T | T2\`, which keeps Option covariant in T.
24
+ * @param defaultValue - A function that returns the value to use if this Option is None
25
+ * @returns The contained value or the default, typed as \`T | T2\`
26
+ */
27
+ getOrElse<T2 extends Type = never>(defaultValue: () => T | T2): T | T2
28
+ /**
29
+ * Returns the contained value or throws an error if None
30
+ * @param error - Optional error to throw, or a builder that makes one (called only on None). If not
31
+ * provided, throws a default error
32
+ * @returns The contained value
33
+ * @throws The specified or built error, or a default error if the Option is None
34
+ */
35
+ orThrow(error?: Error | (() => Error)): T
36
+ /**
37
+ * Returns the contained value, or calls the never-returning handler if None.
38
+ * Use this when you have a helper like \`(msg) => fail(msg, 2)\` that terminates the
39
+ * program — the result type is unconditionally \`T\`, so you avoid the TypeScript
40
+ * narrowing trap where \`if (o.isNone()) fail(...)\` fails to narrow \`o.value\` when
41
+ * \`fail\` is an arrow function typed as \`(...): never\`.
42
+ */
43
+ expect(handler: () => never): T
44
+ /**
45
+ * Returns this Option if it contains a value, otherwise calls \`alternative\` for another Option.
46
+ * The alternative is lazy: it runs only on None. It may hold a different type; the result
47
+ * widens to \`Option<T | T2>\`.
48
+ * @param alternative - A function that returns the Option to use if this is None
49
+ * @returns This Option or the alternative, typed as \`Option<T | T2>\`
50
+ */
51
+ orElse<T2 extends Type>(alternative: () => Option<T2>): Option<T | T2>
52
+ /**
53
+ * Returns the contained value or null if None
54
+ * @returns The contained value or null
55
+ */
56
+ orNull(): T | null
57
+ /**
58
+ * Returns the contained value or undefined if None
59
+ * @returns The contained value or undefined
60
+ */
61
+ orUndefined(): T | undefined
62
+ /**
63
+ * Maps the value inside the Option using the provided function
64
+ * @param f - The mapping function
65
+ * @returns A new Option containing the mapped value, or None if this Option is None
66
+ */
67
+ map<U extends Type>(f: (value: T) => U): Option<U>
68
+ /**
69
+ * Applies a wrapped function to a wrapped value (Applicative pattern)
70
+ * @param ff - An Option containing a function from T to U
71
+ * @returns A new Option containing the result of applying the function
72
+ */
73
+ ap<U extends Type>(ff: Option<(value: T) => U>): Option<U>
74
+ /**
75
+ * Returns this Option if it contains a value that satisfies the predicate, otherwise returns None
76
+ * @param predicate - The predicate function to test the value
77
+ * @returns This Option or None
78
+ */
79
+ filter(predicate: (value: T) => boolean): Option<T>
80
+ /**
81
+ * Maps the value using a function that returns an Option
82
+ * @param f - The mapping function returning an Option
83
+ * @returns The result of applying f to the contained value, or None if this Option is None
84
+ */
85
+ flatMap<U extends Type>(f: (value: T) => Option<U>): Option<U>
86
+ /**
87
+ * Maps the value using an async function that returns an Option
88
+ * @param f - The async mapping function returning an Option
89
+ * @returns Promise of the result of applying f to the contained value, or None if this Option is None
90
+ */
91
+ flatMapAsync<U extends Type>(f: (value: T) => Promise<Option<U>>): Promise<Option<U>>
92
+ /**
93
+ * Pattern matches over the Option, applying onNone if None and onSome if Some
94
+ * @param onNone - Function to apply if the Option is None
95
+ * @param onSome - Function to apply if the Option has a value
96
+ * @returns The result of applying the appropriate function
97
+ */
98
+ fold<U>(onNone: () => U, onSome: (value: T) => U): U
99
+ /**
100
+ * Async variant of fold. Accepts sync or async handlers on either branch and
101
+ * always returns a Promise.
102
+ */
103
+ foldAsync<U>(onNone: () => U | Promise<U>, onSome: (value: T) => U | Promise<U>): Promise<U>
104
+ /**
105
+ * Left-associative fold using the provided zero value and operation
106
+ * @param z - Zero/identity value
107
+ * @returns A function that takes an operation to apply
108
+ */
109
+ foldLeft<B>(z: B): (op: (b: B, a: T) => B) => B
110
+ /**
111
+ * Right-associative fold using the provided zero value and operation
112
+ * @param z - Zero/identity value
113
+ * @returns A function that takes an operation to apply
114
+ */
115
+ foldRight<B>(z: B): (op: (a: T, b: B) => B) => B
116
+ /**
117
+ * Checks if this Option contains the specified value
118
+ * @param value - The value to check for
119
+ * @returns true if this Option contains the value, false otherwise
120
+ */
121
+ contains(value: T): boolean
122
+ /**
123
+ * Tests whether the value, if there is one, satisfies the predicate. The dual of \`exists\`, and
124
+ * Scala's \`forall\`: \`None\` gives \`true\`, the same way \`[].every(p)\` does.
125
+ * @param p - The predicate to test the value with
126
+ * @returns \`true\` for None, otherwise \`p(value)\`
127
+ * @example
128
+ * \`\`\`typescript
129
+ * Option("abc").every((s) => s.length > 2) // true
130
+ * Option<string>(undefined).every((s) => s.length > 2) // true: nothing to fail
131
+ * \`\`\`
132
+ */
133
+ every(p: (a: T) => boolean): boolean
134
+ /**
135
+ * Converts this Option to a List.
136
+ * @returns A List containing the value if Some, or empty List if None
137
+ */
138
+ toList(): List<T>
139
+ /**
140
+ * Converts this Option to a plain readonly array.
141
+ * @returns \`[value]\` if Some, \`[]\` if None. Symmetric with \`toList()\` but
142
+ * skips the List wrapper for code that just wants Array-prototype methods
143
+ * or spread into another array.
144
+ */
145
+ toArray(): readonly T[]
146
+ /** The number of elements in this Option (0 or 1) */
147
+ size: number
148
+ /**
149
+ * Converts this Option to an Either
150
+ * @param leftOrBuilder - The Left value to use if None, or a thunk producing it.
151
+ * Pass a thunk when the Left value is expensive to construct or carries
152
+ * context (e.g. \`() => ConfigError(missing)\`) so the cost is paid only
153
+ * on the None path. Eager value is fine for cheap errors.
154
+ * @returns Right(value) if Some, else Left(leftOrBuilder()) / Left(leftOrBuilder)
155
+ */
156
+ toEither<E>(leftOrBuilder: E | (() => E)): Either<E, T>
157
+ /**
158
+ * Returns a string representation of this Option
159
+ * @returns A string representation
160
+ */
161
+ toString(): string
162
+ /**
163
+ * Returns a simple object representation of this Option
164
+ * @returns An object with _tag and value properties
165
+ */
166
+ toValue(): { _tag: "Some" | "None"; value: T }
167
+ /**
168
+ * Custom JSON serialization producing the canonical \`@functype\`-marked
169
+ * envelope so native \`JSON.stringify\` recursion (e.g. inside a plain
170
+ * object) emits a round-trip-able shape.
171
+ */
172
+ toJSON(): { "@functype": "Option"; _tag: "Some" | "None"; value: T | null }
173
+ /**
174
+ * Pattern matches over the Option, applying a handler function based on the variant
175
+ * @param patterns - Object with handler functions for Some and None variants
176
+ * @returns The result of applying the matching handler function
177
+ */
178
+ match<R>(patterns: { Some: (value: T) => R; None: () => R }): R
179
+ }
180
+
181
+ export interface SomeOf<out T extends Type> extends OptionBase<T> {
182
+ readonly _tag: "Some"
183
+ readonly value: T
184
+ readonly isEmpty: false
185
+ }
186
+
187
+ export interface NoneOf<out T extends Type> extends OptionBase<T> {
188
+ readonly _tag: "None"
189
+ readonly value: undefined
190
+ readonly isEmpty: true
191
+ }`,Either:`export type Either<L extends Type, R extends Type> = LeftOf<L, R> | RightOf<L, R>
192
+
193
+ export interface EitherBase<out L extends Type, out R extends Type>
194
+ extends FunctypeSum<R, "Left" | "Right">, Promisable<R>, Doable<R>, Reshapeable<R>, Extractable<R> {
195
+ isLeft(): this is LeftOf<L, R>
196
+ isRight(): this is RightOf<L, R>
197
+ /**
198
+ * Returns the Right value, or calls \`defaultValue\` on a Left. The default is lazy: it runs only
199
+ * on a Left. A default that fits \`R\` keeps \`R\`, so a literal union is not widened; a default of
200
+ * another type widens the result to \`R | R2\`.
201
+ */
202
+ getOrElse<R2 extends Type = never>(defaultValue: () => R | R2): R | R2
203
+ /**
204
+ * Returns the Right value, or throws on a Left. Pass an \`Error\` to throw it, or a builder to make one
205
+ * from the Left value — for code that must throw for a host (a retrying step runner, an MCP tool, a
206
+ * React Query \`queryFn\`). With no argument, throws the Left value itself.
207
+ */
208
+ orThrow(error?: Error | ((left: L) => Error)): R
209
+ /**
210
+ * Returns the right value, or calls the never-returning handler with the Left's value.
211
+ * Use this when you have a helper like \`(msg) => fail(msg, 2)\` that terminates the
212
+ * program — the result type is unconditionally \`R\`, so you avoid the TypeScript
213
+ * narrowing trap where \`if (e.isLeft()) fail(...)\` fails to narrow \`e.value\` when
214
+ * \`fail\` is an arrow function typed as \`(...): never\`.
215
+ */
216
+ expect(handler: (value: L) => never): R
217
+ /**
218
+ * Returns this Either if it is a Right, otherwise calls \`alternative\` for another Either.
219
+ * The alternative is lazy: it runs only on a Left.
220
+ */
221
+ orElse<L2 extends Type, R2 extends Type>(alternative: () => Either<L2, R2>): Either<L | L2, R | R2>
222
+ orNull(): R | null
223
+ orUndefined(): R | undefined
224
+ map<U extends Type>(f: (value: R) => U): Either<L, U>
225
+ ap<L2 extends Type, U extends Type>(ff: Either<L2, (value: R) => U>): Either<L | L2, U>
226
+ merge<L1 extends Type, R1 extends Type>(other: Either<L1, R1>): Either<L | L1, [R, R1]>
227
+ /**
228
+ * Maps the Right value with an async function. A Left resolves unchanged.
229
+ * If \`f\` rejects or throws, the returned Promise rejects with the same reason: it does not
230
+ * become a Left, and it never throws synchronously. To turn a rejection into a Left, use \`Either.fromPromise(p, onRejected)\`
231
+ * or \`tryCatchAsync\`, which take a function from the reason to \`L\`.
232
+ */
233
+ mapAsync<U extends Type>(f: (value: R) => Promise<U>): Promise<Either<L, U>>
234
+ flatMap<L2 extends Type, U extends Type>(f: (value: R) => Either<L2, U>): Either<L | L2, U>
235
+ /**
236
+ * Chains an async function that returns an Either. A Left resolves unchanged.
237
+ * If \`f\` rejects or throws, the returned Promise rejects with the same reason, as with \`mapAsync\`.
238
+ */
239
+ flatMapAsync<L2 extends Type, U extends Type>(f: (value: R) => Promise<Either<L2, U>>): Promise<Either<L | L2, U>>
240
+ toOption(): Option<R>
241
+ toString(): string
242
+ [Symbol.iterator]: () => Iterator<R>
243
+ yield(): Generator<R, void, unknown>
244
+ traverse<L2 extends Type, U extends Type>(f: (value: R) => Either<L2, U>): Either<L | L2, U[]>
245
+ tap(f: (value: R) => void): Either<L, R>
246
+ tapLeft(f: (value: L) => void): Either<L, R>
247
+ mapLeft<L2 extends Type>(f: (value: L) => L2): Either<L2, R>
248
+ /**
249
+ * Applies a predicate to the Right value. If the predicate fails, short-circuits
250
+ * to a Left carrying the value produced by \`onUnsatisfied\`. Left passes through
251
+ * unchanged (predicate not evaluated). Lets you turn a value-level guard into the
252
+ * Left channel without breaking the chain with an \`if/return Left(...)\` ladder.
253
+ * @param predicate - The predicate to test the Right value
254
+ * @param onUnsatisfied - Builds the new Left value when the predicate fails
255
+ * @returns Right if the predicate holds, Left(onUnsatisfied(value)) otherwise
256
+ */
257
+ filterOrElse<L2 extends Type>(predicate: (value: R) => boolean, onUnsatisfied: (value: R) => L2): Either<L | L2, R>
258
+ bimap<L2 extends Type, R2 extends Type>(fl: (value: L) => L2, fr: (value: R) => R2): Either<L2, R2>
259
+ fold<T extends Type>(onLeft: (value: L) => T, onRight: (value: R) => T): T
260
+ /**
261
+ * Async variant of fold. Accepts sync or async handlers on either branch and
262
+ * always returns a Promise, keeping chains fluent when at least one branch is async.
263
+ */
264
+ foldAsync<T extends Type>(onLeft: (value: L) => T | Promise<T>, onRight: (value: R) => T | Promise<T>): Promise<T>
265
+ swap(): Either<R, L>
266
+ /**
267
+ * Pipes the value through the provided function based on whether this is a Left or Right
268
+ */
269
+ pipeEither<U extends Type>(onLeft: (value: L) => U, onRight: (value: R) => U): U
270
+
271
+ /**
272
+ * Pipes the Either value through the provided function
273
+ */
274
+ pipe<U extends Type>(f: (value: L | R) => U): U
275
+ /**
276
+ * Pattern matches over the Either, applying a handler function based on the variant
277
+ */
278
+ match<T>(patterns: { Left: (value: L) => T; Right: (value: R) => T }): T
279
+ /**
280
+ * Returns the value and tag for inspection
281
+ */
282
+ toValue(): { _tag: "Left" | "Right"; value: L | R }
283
+ /**
284
+ * Custom JSON serialization that excludes getter properties.
285
+ * Emits the canonical functype envelope with \`@functype: "Either"\` so
286
+ * native \`JSON.stringify\` recursion (e.g. inside a plain object body)
287
+ * produces a marker-bearing envelope that survives a round-trip through
288
+ * \`Serialization.deserialize\`.
289
+ */
290
+ toJSON(): { "@functype": "Either"; _tag: "Left" | "Right"; value: L | R }
291
+ }
292
+
293
+ export interface LeftOf<out L extends Type, out R extends Type> extends EitherBase<L, R> {
294
+ readonly _tag: "Left"
295
+ readonly value: L
296
+ }
297
+
298
+ export interface RightOf<out L extends Type, out R extends Type> extends EitherBase<L, R> {
299
+ readonly _tag: "Right"
300
+ readonly value: R
301
+ }`,Try:`export type Try<T> = SuccessOf<T> | FailureOf<T>
302
+
303
+ export interface TryBase<out T>
304
+ extends FunctypeSum<T, TypeNames>, Extractable<T>, Pipe<T>, Promisable<T>, Doable<T>, Reshapeable<T> {
305
+ readonly _tag: TypeNames
306
+ /** The value of a Success; undefined on a Failure */
307
+ readonly value: T | undefined
308
+ /** The error of a Failure; undefined on a Success */
309
+ readonly error: Error | undefined
310
+ isSuccess(): this is SuccessOf<T>
311
+ isFailure(): this is FailureOf<T>
312
+ /**
313
+ * Returns the value, or calls \`defaultValue\` on a Failure. The default is lazy: it runs only on
314
+ * a Failure. A default that fits \`T\` keeps \`T\`, so a literal union is not widened; a default of
315
+ * another type widens the result to \`T | T2\`.
316
+ */
317
+ getOrElse<T2 extends Type = never>(defaultValue: () => T | T2): T | T2
318
+ /**
319
+ * Returns the value, or throws on a Failure. Pass an \`Error\` to throw it, or a builder to make one from
320
+ * the failure's error. With no argument, rethrows the original error.
321
+ */
322
+ orThrow(error?: Error | ((error: Error) => Error)): T
323
+ /**
324
+ * Returns the success value, or calls the never-returning handler with the Failure's error.
325
+ * Use this when you have a helper like \`(msg) => fail(msg, 2)\` that terminates the program —
326
+ * the result type is unconditionally \`T\`, so you avoid the TypeScript narrowing trap where
327
+ * \`if (t.isFailure()) fail(...)\` fails to narrow \`t.value\` when \`fail\` is an arrow function
328
+ * typed as \`(...): never\`.
329
+ */
330
+ expect(handler: (error: Error) => never): T
331
+ /**
332
+ * Returns this Try if it is a Success, otherwise calls \`alternative\` for another Try.
333
+ * The alternative is lazy: it runs only on a Failure.
334
+ */
335
+ orElse<T2 extends Type>(alternative: () => Try<T2>): Try<T | T2>
336
+ orNull(): T | null
337
+ orUndefined(): T | undefined
338
+ toOption(): Option<T>
339
+ /**
340
+ * Converts to a plain readonly array: \`[value]\` for Success, \`[]\` for Failure.
341
+ * Symmetric with \`Try.toList()\` but skips the List wrapper for code that
342
+ * just wants to feed Array.prototype methods or spread into another array.
343
+ */
344
+ toArray(): readonly T[]
345
+ /**
346
+ * Converts to Either<E, T>. Failure becomes Left(builder(error)) when given a function,
347
+ * or Left(leftValue) when given a value. Success becomes Right(value).
348
+ *
349
+ * Prefer the function form to thread the underlying Error's context into the Left:
350
+ *
351
+ * Try(() => JSON.parse(text)).toEither((e) => \`parse failed: \${e.message}\`)
352
+ */
353
+ toEither<E extends Type>(leftOrBuilder: E | ((err: Error) => E)): Either<E, T>
354
+ toTry(): Try<T>
355
+ map<U>(f: (value: T) => U): Try<U>
356
+ ap<U>(ff: Try<(value: T) => U>): Try<U>
357
+ flatMap<U>(f: (value: T) => Try<U>): Try<U>
358
+ flatMapAsync<U>(f: (value: T) => Promise<Try<U>>): Promise<Try<U>>
359
+ /**
360
+ * Pattern matches over the Try, applying onFailure if Failure and onSuccess if Success
361
+ * @param onFailure - Function to apply if the Try is Failure
362
+ * @param onSuccess - Function to apply if the Try is Success
363
+ * @returns The result of applying the appropriate function
364
+ */
365
+ fold<U extends Type>(onFailure: (error: Error) => U, onSuccess: (value: T) => U): U
366
+ /**
367
+ * Async variant of fold. Accepts sync or async handlers on either branch and
368
+ * always returns a Promise.
369
+ */
370
+ foldAsync<U extends Type>(
371
+ onFailure: (error: Error) => U | Promise<U>,
372
+ onSuccess: (value: T) => U | Promise<U>,
373
+ ): Promise<U>
374
+ toString(): string
375
+ /**
376
+ * Pattern matches over the Try, applying a handler function based on the variant
377
+ * @param patterns - Object with handler functions for Success and Failure variants
378
+ * @returns The result of applying the matching handler function
379
+ */
380
+ match<R>(patterns: { Success: (value: T) => R; Failure: (error: Error) => R }): R
381
+ /**
382
+ * Recovers from a Failure by applying a function to the error, returning a new Try.
383
+ * The recovery value may be a wider type; the result is \`Try<T | U>\`, matching
384
+ * Scala's \`recover[U >: T]\` shape so Try stays covariant in T.
385
+ */
386
+ recover<U extends Type>(f: (error: Error) => U): Try<T | U>
387
+ /**
388
+ * Recovers from a Failure by applying a function that returns a new Try.
389
+ * As with \`recover\`, the recovery Try may carry a wider type; the result widens accordingly.
390
+ */
391
+ recoverWith<U extends Type>(f: (error: Error) => Try<U>): Try<T | U>
392
+ /**
393
+ * Applies a predicate to the success value. If the predicate fails, short-circuits
394
+ * to a Failure with the error produced by \`onUnsatisfied\`. Failure passes through
395
+ * unchanged (predicate not evaluated). Lets you turn a value-level guard into the
396
+ * error channel without writing a manual \`throw\` inside a \`Try(() => ...)\` body.
397
+ * @param predicate - The predicate to test the success value
398
+ * @param onUnsatisfied - Builds the Error for the new Failure when the predicate fails
399
+ * @returns A Success if the predicate holds, a Failure carrying \`onUnsatisfied(value)\` otherwise
400
+ */
401
+ filterOrElse(predicate: (value: T) => boolean, onUnsatisfied: (value: T) => Error): Try<T>
402
+ toValue(): { _tag: TypeNames; value: T | Error }
403
+ /**
404
+ * Custom JSON serialization. Success emits \`{"@functype":"Try","_tag":"Success","value":T}\`.
405
+ * Failure emits \`{"@functype":"Try","_tag":"Failure","error":SerializedError}\` where
406
+ * SerializedError captures \`name\`, \`message\`, \`stack\`, and the full \`cause\` chain —
407
+ * \`e.name\` survives round-trip but \`instanceof SomeError\` does not.
408
+ */
409
+ toJSON():
410
+ { "@functype": "Try"; _tag: "Success"; value: T } | { "@functype": "Try"; _tag: "Failure"; error: SerializedError }
411
+ }
412
+
413
+ export interface SuccessOf<out T> extends TryBase<T> {
414
+ readonly _tag: "Success"
415
+ readonly value: T
416
+ readonly error: undefined
417
+ }
418
+
419
+ export interface FailureOf<out T> extends TryBase<T> {
420
+ readonly _tag: "Failure"
421
+ readonly value: undefined
422
+ readonly error: Error
423
+ }`,List:`export interface List<out A> extends FunctypeCollection<A, "List">, Doable<A>, Reshapeable<A> {
424
+ readonly length: number
425
+ [Symbol.iterator](): Iterator<A>
426
+ // Override these to return List instead of FunctypeCollection
427
+ map<B>(f: (a: A) => B): List<B>
428
+ ap<B>(ff: List<(value: A) => B>): List<B>
429
+ flatMap<B>(f: (a: A) => Iterable<B>): List<B>
430
+ /** Async flatMap. Starts every call at once unless \`options.concurrency\` caps it; \`{ concurrency: 1 }\` runs them in order. */
431
+ flatMapAsync<B>(f: (a: A) => PromiseLike<Iterable<B>>, options?: ConcurrencyOptions): PromiseLike<List<B>>
432
+ /**
433
+ * Async map: awaits \`f\` for each element and keeps the results in input order.
434
+ *
435
+ * Runs one call at a time by default, which is what replacing a loop that awaits needs. Pass
436
+ * \`{ concurrency: n }\` to allow up to \`n\` calls at once, or \`"unbounded"\` to start them all together.
437
+ * (\`flatMapAsync\` defaults to \`"unbounded"\`; it keeps that default so existing callers don't change.)
438
+ * A rejection rejects the result, and no further calls start.
439
+ *
440
+ * @example
441
+ * \`\`\`typescript
442
+ * const users = await List(ids).mapAsync(fetchUser) // in order, one at a time
443
+ * const pages = await List(urls).mapAsync(fetchPage, { concurrency: 4 }) // up to 4 at once
444
+ * \`\`\`
445
+ */
446
+ mapAsync<B>(f: (a: A) => PromiseLike<B>, options?: ConcurrencyOptions): Promise<List<B>>
447
+ // Override filter for type guard support
448
+ filter<S extends A>(predicate: (a: A) => a is S): List<S>
449
+ filter(predicate: (a: A) => unknown): List<A>
450
+ filterNot(p: (a: A) => boolean): List<A>
451
+ // List-specific methods
452
+ /** @internal */
453
+ filterType<T extends Typeable<string, unknown>>(tag: string): List<T & A>
454
+ /** Remove a value. Accepts \`unknown\` so an unrelated-type arg is a safe no-op (Scala: \`-(elem: Any)\`). */
455
+ remove(value: unknown): List<A>
456
+ removeAt(index: number): List<A>
457
+ /** Add a value, possibly widening the element type (Scala: \`:+[B >: A]\`). */
458
+ add<B>(item: B): List<A | B>
459
+ get(index: number): Option<A>
460
+ /** Concatenate with another list, possibly widening (Scala: \`++[B >: A]\`). */
461
+ concat<B>(other: List<B>): List<A | B>
462
+ take(n: number): List<A>
463
+ takeWhile(p: (a: A) => boolean): List<A>
464
+ takeRight(n: number): List<A>
465
+ /** Drop the first \`n\` elements. \`n\` of 0 or less drops nothing. */
466
+ drop(n: number): List<A>
467
+ /** Drop the last \`n\` elements. \`n\` of 0 or less drops nothing. */
468
+ dropRight(n: number): List<A>
469
+ /** Drop elements while \`p\` holds. Gives an empty List when every element matches. */
470
+ dropWhile(p: (a: A) => boolean): List<A>
471
+ /**
472
+ * Spread each element that's an array or another non-string iterable (List, Set, ...) into the result,
473
+ * one level deep, keeping other elements, strings included, as they are.
474
+ * @example
475
+ * \`\`\`typescript
476
+ * List([[1, 2], [3]]).flatten() // List([1, 2, 3])
477
+ * List([List([1]), List([2])]).flatten() // List([1, 2])
478
+ * \`\`\`
479
+ */
480
+ flatten<B = Flattened<A>>(): List<B>
481
+ last(): A | undefined
482
+ lastOption(): Option<A>
483
+ tail(): List<A>
484
+ init(): List<A>
485
+ reverse(): List<A>
486
+ /** Find the index of a value. Accepts \`unknown\` (Scala: \`indexOf(elem: Any)\`). */
487
+ indexOf(value: unknown): number
488
+ /** Prepend a value, possibly widening (Scala: \`+:[B >: A]\`). */
489
+ prepend<B>(item: B): List<A | B>
490
+ distinct(): List<A>
491
+ sorted(compareFn?: (a: A, b: A) => number): List<A>
492
+ sortBy<B>(f: (a: A) => B, compareFn?: (a: B, b: B) => number): List<A>
493
+ zip<B>(other: List<B>): List<[A, B]>
494
+ zipWithIndex(): List<[A, number]>
495
+ groupBy<K>(f: (a: A) => K): globalThis.Map<K, List<A>>
496
+ partition(p: (a: A) => boolean): [List<A>, List<A>]
497
+ span(p: (a: A) => boolean): [List<A>, List<A>]
498
+ slice(start: number, end: number): List<A>
499
+ /**
500
+ * Pattern matches over the List, applying a handler function based on whether it's empty
501
+ * @param patterns - Object with handler functions for Empty and NonEmpty variants
502
+ * @returns The result of applying the matching handler function
503
+ */
504
+ match<R>(patterns: { Empty: () => R; NonEmpty: (values: A[]) => R }): R
505
+ }`,Set:`export interface Set<out A> extends FunctypeCollection<A, "Set">, Collection<A> {
506
+ add<B>(value: B): Set<A | B>
507
+ remove(value: unknown): Set<A>
508
+ has(value: unknown): boolean
509
+ /**
510
+ * Elements in this set or \`other\`. \`other\` can be any iterable: an array, a native Set or a functype Set.
511
+ * Like every Set method, it compares elements as \`has\` does: by SameValueZero, so objects by identity and
512
+ * \`NaN\` equal to \`NaN\`.
513
+ *
514
+ * @example
515
+ * \`\`\`typescript
516
+ * Set([1, 2]).union([2, 3]) // Set([1, 2, 3])
517
+ * \`\`\`
518
+ */
519
+ union<B>(other: Iterable<B>): Set<A | B>
520
+ /** Elements in both this set and \`other\`, in this set's order (native \`intersection\` follows the smaller set's). */
521
+ intersection(other: Iterable<unknown>): Set<A>
522
+ /** Elements in this set and not in \`other\`. */
523
+ difference(other: Iterable<unknown>): Set<A>
524
+ /** Elements in exactly one of this set and \`other\`. */
525
+ symmetricDifference<B>(other: Iterable<B>): Set<A | B>
526
+ /** True if every element of this set is in \`other\`. True for an empty set. */
527
+ isSubsetOf(other: Iterable<unknown>): boolean
528
+ /** True if every element of \`other\` is in this set. */
529
+ isSupersetOf(other: Iterable<unknown>): boolean
530
+ /** True if this set and \`other\` share no element. */
531
+ isDisjointFrom(other: Iterable<unknown>): boolean
532
+ map<B>(f: (a: A) => B): Set<B>
533
+ flatMap<B>(f: (a: A) => Iterable<B>): Set<B>
534
+ /**
535
+ * Async map: awaits \`f\` for each element and collects the results into a Set, so equal results
536
+ * collapse into one. Runs one call at a time by default; pass \`{ concurrency: n }\` to allow up to
537
+ * \`n\` at once, or \`"unbounded"\`. A rejection rejects the result, and no further calls start.
538
+ */
539
+ mapAsync<B>(f: (a: A) => PromiseLike<B>, options?: ConcurrencyOptions): Promise<Set<B>>
540
+ filter(p: (a: A) => boolean): Set<A>
541
+ filterNot(p: (a: A) => boolean): Set<A>
542
+ // Positional methods follow insertion order. Override them to return Set instead of FunctypeCollection.
543
+ /** Keep the first \`n\` elements. \`n\` of 0 or less keeps none. */
544
+ take(n: number): Set<A>
545
+ takeWhile(p: (a: A) => boolean): Set<A>
546
+ /** Keep the last \`n\` elements. \`n\` of 0 or less keeps none. */
547
+ takeRight(n: number): Set<A>
548
+ /** Drop the first \`n\` elements. \`n\` of 0 or less drops nothing. */
549
+ drop(n: number): Set<A>
550
+ /** Drop the last \`n\` elements. \`n\` of 0 or less drops nothing. */
551
+ dropRight(n: number): Set<A>
552
+ dropWhile(p: (a: A) => boolean): Set<A>
553
+ tail(): Set<A>
554
+ init(): Set<A>
555
+ /**
556
+ * Spread each element that's an array or another non-string iterable into the result, one level deep,
557
+ * keeping other elements, strings included, as they are.
558
+ */
559
+ flatten<B = Flattened<A>>(): Set<B>
560
+ fold<B>(initial: B, fn: (acc: B, a: A) => B): B
561
+ toList(): List<A>
562
+ toSet(): Set<A>
563
+ toArray<B = A>(): B[]
564
+ toString(): string
565
+ }`,Map:`export interface Map<K, out V>
566
+ extends
567
+ KVTraversable<Tuple<[K, V]>>,
568
+ Collection<Tuple<[K, V]>>,
569
+ Typeable<"Map">,
570
+ Serializable<[K, V][]>,
571
+ Pipe<[K, V][]>,
572
+ Foldable<Tuple<[K, V]>>,
573
+ Iterable<[K, V]> {
574
+ readonly [Symbol.toStringTag]: string
575
+ readonly _tag: "Map"
576
+ add(item: Tuple<[K, V]>): Map<K, V>
577
+ remove(value: K): Map<K, V>
578
+ map<U>(f: (value: V) => U): Map<K, U>
579
+ ap<U>(ff: Map<K, (value: V) => U>): Map<K, U>
580
+ flatMap<K2, V2>(f: (entry: Tuple<[K, V]>) => Iterable<[K2, V2]>): Map<K2, V2>
581
+ flatMapAsync<U>(f: (value: V) => PromiseLike<Map<K, U>>): PromiseLike<Map<K, U>>
582
+ get(key: K): Option<V>
583
+ /**
584
+ * Whether the map holds an entry for \`key\`. Keys compare like a native \`Map\`:
585
+ * by identity for objects, by \`SameValueZero\` otherwise.
586
+ *
587
+ * True even when the stored value is \`undefined\`, where \`get(key)\` returns \`None\`.
588
+ * For an entry check (key and value), use \`contains(Tuple([k, v]))\`, which
589
+ * compares the value with \`===\`.
590
+ * @param key - The key to look up
591
+ * @returns true if the map has an entry for \`key\`
592
+ */
593
+ has(key: K): boolean
594
+ /**
595
+ * The keys, in insertion order. A List, like \`Obj.keys()\`.
596
+ * @returns A List of the map's keys
597
+ */
598
+ keys(): List<K>
599
+ /**
600
+ * The values, in insertion order. Duplicates are kept.
601
+ * @returns A List of the map's values
602
+ */
603
+ values(): List<V>
604
+ /** Returns the value for \`key\`, or calls \`defaultValue\` if the key is absent. The default is lazy. */
605
+ getOrElse(key: K, defaultValue: () => V): V
606
+ /** Returns \`Some(value)\` for \`key\`, or calls \`alternative\` for an Option if the key is absent. */
607
+ orElse(key: K, alternative: () => Option<V>): Option<V>
608
+ fold<B>(initial: B, fn: (acc: B, a: Tuple<[K, V]>) => B): B
609
+ foldLeft<B>(z: B): (op: (b: B, a: Tuple<[K, V]>) => B) => B
610
+ foldRight<B>(z: B): (op: (a: Tuple<[K, V]>, b: B) => B) => B
611
+ /**
612
+ * Pattern matches over the Map, applying a handler function based on whether it's empty
613
+ * @param patterns - Object with handler functions for Empty and NonEmpty variants
614
+ * @returns The result of applying the matching handler function
615
+ */
616
+ match<R>(patterns: { Empty: () => R; NonEmpty: (entries: Array<Tuple<[K, V]>>) => R }): R
617
+ toValue(): { _tag: "Map"; value: [K, V][] }
618
+ }`,Lazy:`export interface Lazy<out T extends Type> extends FunctypeBase<T, "Lazy">, Extractable<T>, Pipe<T> {
619
+ /** Tag identifying this as a Lazy type */
620
+ readonly _tag: "Lazy"
621
+ /** Whether the computation has been evaluated */
622
+ readonly isEvaluated: boolean
623
+ /**
624
+ * Returns the computed value, or calls \`defaultValue\` if the computation fails.
625
+ * The default is lazy: it runs only on failure. A default that fits \`T\` keeps \`T\`, so a literal
626
+ * union is not widened; a default of another type widens the result to \`T | T2\`
627
+ * (Scala: \`getOrElse[B >: A](default: => B): B\`).
628
+ */
629
+ getOrElse<T2 extends Type = never>(defaultValue: () => T | T2): T | T2
630
+ /**
631
+ * Returns the computed value or null if computation fails
632
+ * @returns The computed value or null
633
+ */
634
+ orNull(): T | null
635
+ /**
636
+ * Returns the computed value or throws an error if computation fails
637
+ * @param error - Optional custom error to throw. If not provided, throws the computation error or a default error
638
+ * @returns The computed value
639
+ * @throws The specified error, computation error, or a default error
640
+ */
641
+ orThrow(error?: Error): T
642
+ /**
643
+ * Returns this Lazy if computation succeeds, otherwise calls \`alternative\` for another Lazy.
644
+ * The alternative is lazy: it runs only on failure. It may carry a different type; result is \`Lazy<T | T2>\`.
645
+ */
646
+ orElse<T2 extends Type>(alternative: () => Lazy<T2>): Lazy<T | T2>
647
+ /**
648
+ * Maps the value inside the Lazy using the provided function
649
+ * @param f - The mapping function
650
+ * @returns A new Lazy containing the mapped value
651
+ */
652
+ map<U extends Type>(f: (value: T) => U): Lazy<U>
653
+ /**
654
+ * Applies a wrapped function to a wrapped value (Applicative pattern)
655
+ * @param ff - A Lazy containing a function from T to U
656
+ * @returns A new Lazy containing the result
657
+ */
658
+ ap<U extends Type>(ff: Lazy<(value: T) => U>): Lazy<U>
659
+ /**
660
+ * Maps the value inside the Lazy using an async function
661
+ * @param f - The async mapping function
662
+ * @returns A Promise of a new Lazy containing the mapped value
663
+ */
664
+ mapAsync<U extends Type>(f: (value: T) => Promise<U>): Promise<Lazy<U>>
665
+ /**
666
+ * Maps the value using a function that returns a Lazy
667
+ * @param f - The mapping function returning a Lazy
668
+ * @returns A new Lazy containing the flattened result
669
+ */
670
+ flatMap<U extends Type>(f: (value: T) => Lazy<U>): Lazy<U>
671
+ /**
672
+ * Maps the value using an async function that returns a Lazy
673
+ * @param f - The async mapping function returning a Lazy
674
+ * @returns A Promise of a new Lazy containing the flattened result
675
+ */
676
+ flatMapAsync<U extends Type>(f: (value: T) => Promise<Lazy<U>>): Promise<Lazy<U>>
677
+ /**
678
+ * Returns a Lazy that filters the value based on a predicate
679
+ * @param predicate - The predicate function
680
+ * @returns A Lazy containing an Option of the value
681
+ */
682
+ filter(predicate: (value: T) => boolean): Lazy<Option<T>>
683
+ /**
684
+ * Recovers from a failed computation by providing an alternative value
685
+ * @param f - Function that takes the error and returns a recovery value
686
+ * @returns A new Lazy that will use the recovery function if computation fails
687
+ */
688
+ recover(f: (error: unknown) => T): Lazy<T>
689
+ /**
690
+ * Recovers from a failed computation by providing an alternative Lazy
691
+ * @param f - Function that takes the error and returns a recovery Lazy
692
+ * @returns A new Lazy that will use the recovery Lazy if computation fails
693
+ */
694
+ recoverWith(f: (error: unknown) => Lazy<T>): Lazy<T>
695
+ /**
696
+ * Evaluates the computation and returns it as an Option
697
+ * @returns Some containing the value if successful, None if computation fails
698
+ */
699
+ toOption(): Option<T>
700
+ /**
701
+ * Evaluates the computation and returns it as an Either
702
+ * @returns Right containing the value if successful, Left containing the error if computation fails
703
+ */
704
+ toEither(): Either<unknown, T>
705
+ /**
706
+ * Evaluates the computation and returns it as an Either with a mapped error
707
+ * @param mapError - Function to map the error
708
+ * @returns Right containing the value if successful, Left containing the mapped error if computation fails
709
+ */
710
+ toEitherWith<E>(mapError: (error: unknown) => E): Either<E, T>
711
+ /**
712
+ * Evaluates the computation and returns it as a Try
713
+ * @returns Try containing the result of the computation
714
+ */
715
+ toTry(): Try<T>
716
+ /**
717
+ * Applies an effect function to the value if computation succeeds
718
+ * @param f - The effect function
719
+ * @returns This Lazy for chaining
720
+ */
721
+ tap(f: (value: T) => void): Lazy<T>
722
+ /**
723
+ * Applies an effect function to the error if computation fails
724
+ * @param f - The effect function for errors
725
+ * @returns This Lazy for chaining
726
+ */
727
+ tapError(f: (error: unknown) => void): Lazy<T>
728
+ /**
729
+ * Pattern matching on the Lazy value
730
+ * @param f - Function to apply to the computed value
731
+ * @returns The result of applying f to the computed value
732
+ */
733
+ fold<U>(f: (value: T) => U): U
734
+ /**
735
+ * Pattern matching with success and failure handlers
736
+ * @param onFailure - Function to handle computation failure
737
+ * @param onSuccess - Function to handle successful computation
738
+ * @returns The result of the appropriate handler
739
+ */
740
+ foldWith<U>(onFailure: (error: unknown) => U, onSuccess: (value: T) => U): U
741
+ /**
742
+ * Left fold operation
743
+ * @param z - Initial value
744
+ * @returns Function that takes an operator and applies it
745
+ */
746
+ foldLeft<B>(z: B): (op: (b: B, a: T) => B) => B
747
+ /**
748
+ * Right fold operation
749
+ * @param z - Initial value
750
+ * @returns Function that takes an operator and applies it
751
+ */
752
+ foldRight<B>(z: B): (op: (a: T, b: B) => B) => B
753
+ /**
754
+ * Pattern matching for the Lazy type
755
+ * @param patterns - Object with handler for Lazy pattern
756
+ * @returns The result of the matched handler
757
+ */
758
+ match<R>(patterns: { Lazy: (value: T) => R }): R
759
+ /**
760
+ * Creates a string representation of the Lazy
761
+ * @returns String representation showing evaluation status
762
+ */
763
+ toString(): string
764
+ /**
765
+ * Converts the Lazy to a value object.
766
+ *
767
+ * **Forces the thunk** as a side effect — Lazy serialization (and projection
768
+ * to a plain value object) cannot represent an unevaluated thunk in JSON;
769
+ * forcing is the only way to produce a complete projection. If the thunk
770
+ * threw, the failure is captured in the \`error\` field (real Error, with
771
+ * full prototype intact for in-memory inspection — \`toJSON\` projects to
772
+ * \`SerializedError\` for the wire).
773
+ *
774
+ * Changed in 1.2.0 — pre-1.2.0 Lazy emitted \`{_tag, evaluated, value?}\`
775
+ * without forcing. See \`docs/archive/proposals/serializable-audit-q1-q2.md\`.
776
+ */
777
+ toValue(): { _tag: "Lazy"; value: T } | { _tag: "Lazy"; error: Error }
778
+ /**
779
+ * Custom JSON serialization. Forces the thunk (see \`toValue\` for the
780
+ * side-effect contract). Emits \`{"@functype":"Lazy","_tag":"Lazy","value":T}\`
781
+ * on success, or \`{"@functype":"Lazy","_tag":"Lazy","error":SerializedError}\`
782
+ * if the thunk threw — see error-envelope.ts for round-trip semantics.
783
+ */
784
+ toJSON():
785
+ { "@functype": "Lazy"; _tag: "Lazy"; value: T } | { "@functype": "Lazy"; _tag: "Lazy"; error: SerializedError }
786
+ }`,LazyList:`export interface LazyList<out A extends Type>
787
+ extends Foldable<A>, Pipe<LazyList<A>>, Serializable<LazyList<A>>, Typeable<"LazyList"> {
788
+ readonly [Symbol.toStringTag]: string
789
+ // Iterator protocol
790
+ [Symbol.iterator](): Iterator<A>
791
+
792
+ // Lazy operations
793
+ map<B extends Type>(f: (a: A) => B): LazyList<B>
794
+ flatMap<B extends Type>(f: (a: A) => LazyList<B>): LazyList<B>
795
+ filter(predicate: (a: A) => boolean): LazyList<A>
796
+ take(n: number): LazyList<A>
797
+ drop(n: number): LazyList<A>
798
+ takeWhile(predicate: (a: A) => boolean): LazyList<A>
799
+ dropWhile(predicate: (a: A) => boolean): LazyList<A>
800
+ /** Concatenate with another lazy list, possibly widening (Scala: \`++[B >: A]\`). */
801
+ concat<B extends Type>(other: LazyList<B>): LazyList<A | B>
802
+ zip<B extends Type>(other: LazyList<B>): LazyList<[A, B]>
803
+
804
+ takeRight(n: number): LazyList<A>
805
+ reverse(): LazyList<A>
806
+ distinct(): LazyList<A>
807
+ zipWithIndex(): LazyList<[A, number]>
808
+
809
+ // Element access. Methods, because last, lastOption and init read the whole source
810
+ head(): A | undefined
811
+ headOption(): Option<A>
812
+ last(): A | undefined
813
+ lastOption(): Option<A>
814
+ tail(): LazyList<A>
815
+ init(): LazyList<A>
816
+
817
+ // Foldable
818
+ fold<B>(initial: B, fn: (acc: B, a: A) => B): B
819
+
820
+ // Terminal operations (force evaluation)
821
+ toList(): List<A>
822
+ toArray(): A[]
823
+ forEach(f: (a: A) => void): void
824
+ reduce<B extends Type>(f: (acc: B, a: A) => B, initial: B): B
825
+ find(predicate: (a: A) => boolean): Option<A>
826
+ some(predicate: (a: A) => boolean): boolean
827
+ every(predicate: (a: A) => boolean): boolean
828
+ count(): number
829
+
830
+ // Additional methods for clarity
831
+ toString(): string
832
+ }`,Exit:`export type Exit<E extends Type, A extends Type> =
833
+ SuccessExitOf<E, A> | FailureExitOf<E, A> | DieExitOf<E, A> | InterruptedExitOf<E, A>
834
+
835
+ export interface ExitBase<E extends Type, A extends Type> {
836
+ readonly [Symbol.toStringTag]: string
837
+
838
+ /**
839
+ * Type guard to check if this is a Success
840
+ */
841
+ isSuccess(): this is SuccessExitOf<E, A>
842
+
843
+ /**
844
+ * Type guard to check if this is a Failure
845
+ */
846
+ isFailure(): this is FailureExitOf<E, A>
847
+
848
+ /**
849
+ * Type guard to check if this is a Die (a defect — the carried value is not an \`E\`)
850
+ */
851
+ isDie(): this is DieExitOf<E, A>
852
+
853
+ /**
854
+ * Type guard to check if this is Interrupted
855
+ */
856
+ isInterrupted(): this is InterruptedExitOf<E, A>
857
+
858
+ /**
859
+ * Maps the success value
860
+ */
861
+ map<B extends Type>(f: (a: A) => B): Exit<E, B>
862
+
863
+ /**
864
+ * Maps the error value
865
+ */
866
+ mapError<E2 extends Type>(f: (e: E) => E2): Exit<E2, A>
867
+
868
+ /**
869
+ * Maps both error and success values
870
+ */
871
+ mapBoth<E2 extends Type, B extends Type>(onError: (e: E) => E2, onSuccess: (a: A) => B): Exit<E2, B>
872
+
873
+ /**
874
+ * Flat maps the success value
875
+ */
876
+ flatMap<B extends Type>(f: (a: A) => Exit<E, B>): Exit<E, B>
877
+
878
+ /**
879
+ * Pattern matches over the Exit.
880
+ *
881
+ * \`onDie\` is optional and appended rather than inserted so existing three-argument
882
+ * calls keep compiling. Omitting it routes a defect to \`onFailure\` — the pre-\`Die\`
883
+ * behaviour, where defects were indistinguishable from typed failures. Supply it
884
+ * when the distinction matters; note the value it receives is \`unknown\`, not \`E\`.
885
+ */
886
+ fold<T>(
887
+ onFailure: (e: E) => T,
888
+ onSuccess: (a: A) => T,
889
+ onInterrupted?: (fiberId: string) => T,
890
+ onDie?: (defect: unknown) => T,
891
+ ): T
892
+
893
+ /**
894
+ * Pattern matches over the Exit with object patterns.
895
+ *
896
+ * \`Die\` is optional for the same back-compat reason as {@link fold}'s \`onDie\`, and
897
+ * falls back to \`Failure\` when absent.
898
+ */
899
+ match<T>(patterns: {
900
+ Success: (value: A) => T
901
+ Failure: (error: E) => T
902
+ Interrupted: (fiberId: string) => T
903
+ Die?: (defect: unknown) => T
904
+ }): T
905
+
906
+ /**
907
+ * Returns the success value or throws
908
+ */
909
+ orThrow(): A
910
+
911
+ /**
912
+ * Returns the success value, or calls \`defaultValue\` for any other outcome.
913
+ * The default is lazy: it runs only when the Exit is not a Success.
914
+ */
915
+ getOrElse(defaultValue: () => A): A
916
+
917
+ /**
918
+ * Converts to Option (Some for Success, None otherwise)
919
+ */
920
+ toOption(): Option<A>
921
+
922
+ /**
923
+ * Converts to Either (Right for Success, Left for Failure)
924
+ * Throws if Interrupted
925
+ *
926
+ * A \`Die\` becomes \`Left(defect)\`, which widens the Left beyond \`E\`. (\`IO.run()\` rejects on a
927
+ * \`Die\` instead, so its Left stays an \`E\`.) Use {@link isDie} first if the distinction matters.
928
+ */
929
+ toEither(): Either<E, A>
930
+
931
+ /**
932
+ * Returns the raw value for inspection
933
+ */
934
+ toValue(): { _tag: ExitTag; value?: A; error?: E; defect?: unknown; fiberId?: string }
935
+
936
+ /**
937
+ * String representation
938
+ */
939
+ toString(): string
940
+
941
+ /**
942
+ * JSON serialization
943
+ */
944
+ toJSON(): { _tag: ExitTag; value?: A; error?: E; defect?: unknown; fiberId?: string }
945
+ }
946
+
947
+ export interface SuccessExitOf<E extends Type, A extends Type> extends ExitBase<E, A> {
948
+ readonly _tag: "Success"
949
+ readonly value: A
950
+ }
951
+
952
+ export interface FailureExitOf<E extends Type, A extends Type> extends ExitBase<E, A> {
953
+ readonly _tag: "Failure"
954
+ readonly error: E
955
+ }
956
+
957
+ export interface DieExitOf<E extends Type, A extends Type> extends ExitBase<E, A> {
958
+ readonly _tag: "Die"
959
+ readonly defect: unknown
960
+ }
961
+
962
+ export interface InterruptedExitOf<E extends Type, A extends Type> extends ExitBase<E, A> {
963
+ readonly _tag: "Interrupted"
964
+ readonly fiberId: string
965
+ }`,Tuple:`export interface Tuple<out T extends Type[]>
966
+ extends Foldable<T[number]>, Pipe<Tuple<T>>, Serializable<Tuple<T>>, Typeable<"Tuple"> {
967
+ readonly [Symbol.toStringTag]: string
968
+ get<K extends number>(index: K): T[K]
969
+
970
+ fold<B>(initial: B, fn: (acc: B, a: T[number]) => B): B
971
+
972
+ map<U extends Type[]>(f: (value: T) => U): Tuple<U>
973
+
974
+ flatMap<U extends Type[]>(f: (value: T) => Tuple<U>): Tuple<U>
975
+
976
+ toArray(): T
977
+
978
+ readonly length: number
979
+
980
+ [Symbol.iterator](): Iterator<T[number]>
981
+
982
+ toString(): string
983
+
984
+ toValue(): { _tag: "Tuple"; value: T }
985
+ }`,Stack:`export type Stack<A extends Type> = {
986
+ readonly [Symbol.toStringTag]: string
987
+ /**
988
+ * Push a value onto the top of the stack. The value may be a wider type;
989
+ * the result widens to \`Stack<A | B>\` (Scala: \`:+[B >: A]\`).
990
+ * @param value - The value to push
991
+ * @returns A new Stack with the value added
992
+ */
993
+ push<B extends Type>(value: B): Stack<A | B>
994
+
995
+ /**
996
+ * Remove and return the top value from the stack
997
+ * @returns A tuple containing the new Stack and the value
998
+ */
999
+ pop(): [Stack<A>, Option<A>]
1000
+
1001
+ /**
1002
+ * Return the top value without removing it
1003
+ * @returns The top value wrapped in an Option
1004
+ */
1005
+ peek(): Option<A>
1006
+
1007
+ /**
1008
+ * Transforms each element in the stack using the provided function
1009
+ * @param f - The mapping function
1010
+ * @returns A new Stack with transformed elements
1011
+ */
1012
+ map<B extends Type>(f: (a: A) => B): Stack<B>
1013
+
1014
+ /**
1015
+ * Maps each element to a Stack and flattens the result
1016
+ * @param f - The mapping function returning a Stack
1017
+ * @returns A new flattened Stack
1018
+ */
1019
+ flatMap<B extends Type>(f: (a: A) => Stack<B>): Stack<B>
1020
+
1021
+ /**
1022
+ * Applies a Stack of functions to this Stack
1023
+ * @param ff - Stack of functions to apply
1024
+ * @returns A new Stack with applied functions
1025
+ */
1026
+ ap<B extends Type>(ff: Stack<(value: A) => B>): Stack<B>
1027
+
1028
+ /**
1029
+ * Maps each element to an async Stack and flattens the result
1030
+ * @param f - The async mapping function returning a Stack
1031
+ * @returns A promise of the new flattened Stack
1032
+ */
1033
+ flatMapAsync<B extends Type>(f: (value: A) => PromiseLike<Stack<B>>): PromiseLike<Stack<B>>
1034
+
1035
+ /**
1036
+ * Convert the stack to a List
1037
+ * @returns A List containing all elements
1038
+ */
1039
+ toList(): List<A>
1040
+
1041
+ /**
1042
+ * Convert the stack to an array
1043
+ * @returns An array of all elements
1044
+ */
1045
+ toArray(): A[]
1046
+
1047
+ /**
1048
+ * Returns a string representation of the stack
1049
+ * @returns A string representation
1050
+ */
1051
+ toString(): string
1052
+
1053
+ /**
1054
+ * Left-associative fold over all elements using an initial value and combining function.
1055
+ */
1056
+ fold<B>(initial: B, fn: (acc: B, a: A) => B): B
1057
+
1058
+ /**
1059
+ * Pattern matches over the Stack, applying a handler function based on whether it's empty
1060
+ * @param patterns - Object with handler functions for Empty and NonEmpty variants
1061
+ * @returns The result of applying the matching handler function
1062
+ */
1063
+ match<R>(patterns: { Empty: () => R; NonEmpty: (values: A[]) => R }): R
1064
+ } & Traversable<A> &`,HttpError:`export type HttpError = NetworkError | HttpStatusError | DecodeError`,Http:`export interface HttpClientConfig {
1065
+ readonly baseUrl?: string
1066
+ readonly defaultHeaders?: Record<string, string>
1067
+ readonly fetch?: typeof globalThis.fetch
1068
+ /**
1069
+ * Effectful transformer that runs after \`defaultHeaders\` and per-call headers
1070
+ * are merged, but before the request is sent. Returning a failed IO short-
1071
+ * circuits the call with the produced \`HttpError\`. Compose multiple concerns
1072
+ * (request IDs, auth refresh, logging) with standard IO operators — the
1073
+ * request side becomes symmetric with the response chain (\`.tap\`, \`.map\`,
1074
+ * \`.flatMap\`, \`.catchTag\`).
1075
+ *
1076
+ * @example
1077
+ * \`\`\`ts
1078
+ * const addRequestId = (r: HttpRequestView): HttpRequestView => ({
1079
+ * ...r,
1080
+ * headers: { ...r.headers, "x-request-id": crypto.randomUUID() },
1081
+ * })
1082
+ *
1083
+ * const addBearer = (getToken: () => Promise<string>) =>
1084
+ * (r: HttpRequestView): IO<never, HttpError, HttpRequestView> =>
1085
+ * IO.tryPromise({
1086
+ * try: () => getToken(),
1087
+ * catch: (e) => HttpError.networkError(r.url, r.method, e),
1088
+ * }).map((token) => ({
1089
+ * ...r,
1090
+ * headers: { ...r.headers, Authorization: \`Bearer \${token}\` },
1091
+ * }))
1092
+ *
1093
+ * const api = Http.client({
1094
+ * baseUrl: "https://api.example.com",
1095
+ * beforeRequest: (r) =>
1096
+ * IO.succeed(r)
1097
+ * .map(addRequestId)
1098
+ * .flatMap(addBearer(getToken))
1099
+ * .tap((req) => logger.info(req.method, req.url)),
1100
+ * })
1101
+ * \`\`\`
1102
+ */
1103
+ readonly beforeRequest?: (request: HttpRequestView) => IO<never, HttpError, HttpRequestView>
1104
+
1105
+ /**
1106
+ * Effectful transformer that runs after the response is parsed (and the
1107
+ * decoder, if any, succeeds) but before the IO resolves to the caller.
1108
+ * Returning a failed IO surfaces the error in place of the response.
1109
+ *
1110
+ * **Only runs on the success path.** \`HttpStatusError\` (non-2xx),
1111
+ * \`DecodeError\` (validation failure), and \`NetworkError\` (fetch / abort)
1112
+ * skip this hook and surface directly. For *error*-side observability and
1113
+ * recovery (refresh-on-401, error logging), use \`.catchTag(...)\` /
1114
+ * \`.tapError(...)\` at the call site.
1115
+ *
1116
+ * The hook receives \`HttpResponse<unknown>\` — body shape is opaque here
1117
+ * because hooks are response-shape-agnostic. The per-call decoder narrows
1118
+ * \`data\` to the typed value before the response reaches the caller, but
1119
+ * the hook itself sees \`unknown\`.
1120
+ *
1121
+ * @example
1122
+ * \`\`\`ts
1123
+ * const api = Http.client({
1124
+ * baseUrl: "https://api.example.com",
1125
+ * afterResponse: (response) =>
1126
+ * IO.succeed(response)
1127
+ * .tap((r) => logger.info("response", { status: r.status }))
1128
+ * .map((r) => ({ ...r, headers: redactSensitiveHeaders(r.headers) })),
1129
+ * })
1130
+ *
1131
+ * // Refresh-on-401 is a .catchTag pattern, NOT an afterResponse pattern:
1132
+ * api.get("/me", { decode })
1133
+ * .catchTag("HttpStatusError", (e) =>
1134
+ * e.status === 401 ? refreshToken().flatMap(() => api.get("/me", { decode })) : IO.fail(e),
1135
+ * )
1136
+ * \`\`\`
1137
+ */
1138
+ readonly afterResponse?: (response: HttpResponse<unknown>) => IO<never, HttpError, HttpResponse<unknown>>
1139
+ }`};export{e as FULL_INTERFACES};