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