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.
- package/README.md +63 -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 +1139 -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 +279 -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 +1243 -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 +7 -12
- 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-0XJEOHi_.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-BTLBc-KK.js +0 -10
- package/dist/typeclass-C61yDVYd.js +0 -1
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { Either } from "../either/index.js";
|
|
2
|
+
import { Option } from "../option/index.js";
|
|
3
|
+
import { Type } from "../types/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Exit type module - represents the outcome of running an IO effect.
|
|
6
|
+
* @module Exit
|
|
7
|
+
* @category IO
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Possible outcome types for an Exit
|
|
11
|
+
*/
|
|
12
|
+
export type ExitTag = "Success" | "Failure" | "Die" | "Interrupted";
|
|
13
|
+
/**
|
|
14
|
+
* What every Exit has, whichever variant it is. `Exit<E, A>` is the union of the four variants, so
|
|
15
|
+
* TypeScript narrows it on the guards and on `_tag`.
|
|
16
|
+
*/
|
|
17
|
+
export interface ExitBase<E extends Type, A extends Type> {
|
|
18
|
+
readonly [Symbol.toStringTag]: string;
|
|
19
|
+
/**
|
|
20
|
+
* Type guard to check if this is a Success
|
|
21
|
+
*/
|
|
22
|
+
isSuccess(): this is SuccessExitOf<E, A>;
|
|
23
|
+
/**
|
|
24
|
+
* Type guard to check if this is a Failure
|
|
25
|
+
*/
|
|
26
|
+
isFailure(): this is FailureExitOf<E, A>;
|
|
27
|
+
/**
|
|
28
|
+
* Type guard to check if this is a Die (a defect — the carried value is not an `E`)
|
|
29
|
+
*/
|
|
30
|
+
isDie(): this is DieExitOf<E, A>;
|
|
31
|
+
/**
|
|
32
|
+
* Type guard to check if this is Interrupted
|
|
33
|
+
*/
|
|
34
|
+
isInterrupted(): this is InterruptedExitOf<E, A>;
|
|
35
|
+
/**
|
|
36
|
+
* Maps the success value
|
|
37
|
+
*/
|
|
38
|
+
map<B extends Type>(f: (a: A) => B): Exit<E, B>;
|
|
39
|
+
/**
|
|
40
|
+
* Maps the error value
|
|
41
|
+
*/
|
|
42
|
+
mapError<E2 extends Type>(f: (e: E) => E2): Exit<E2, A>;
|
|
43
|
+
/**
|
|
44
|
+
* Maps both error and success values
|
|
45
|
+
*/
|
|
46
|
+
mapBoth<E2 extends Type, B extends Type>(onError: (e: E) => E2, onSuccess: (a: A) => B): Exit<E2, B>;
|
|
47
|
+
/**
|
|
48
|
+
* Flat maps the success value
|
|
49
|
+
*/
|
|
50
|
+
flatMap<B extends Type>(f: (a: A) => Exit<E, B>): Exit<E, B>;
|
|
51
|
+
/**
|
|
52
|
+
* Pattern matches over the Exit.
|
|
53
|
+
*
|
|
54
|
+
* `onDie` is optional and appended rather than inserted so existing three-argument
|
|
55
|
+
* calls keep compiling. Omitting it routes a defect to `onFailure` — the pre-`Die`
|
|
56
|
+
* behaviour, where defects were indistinguishable from typed failures. Supply it
|
|
57
|
+
* when the distinction matters; note the value it receives is `unknown`, not `E`.
|
|
58
|
+
*/
|
|
59
|
+
fold<T>(onFailure: (e: E) => T, onSuccess: (a: A) => T, onInterrupted?: (fiberId: string) => T, onDie?: (defect: unknown) => T): T;
|
|
60
|
+
/**
|
|
61
|
+
* Pattern matches over the Exit with object patterns.
|
|
62
|
+
*
|
|
63
|
+
* `Die` is optional for the same back-compat reason as {@link fold}'s `onDie`, and
|
|
64
|
+
* falls back to `Failure` when absent.
|
|
65
|
+
*/
|
|
66
|
+
match<T>(patterns: {
|
|
67
|
+
Success: (value: A) => T;
|
|
68
|
+
Failure: (error: E) => T;
|
|
69
|
+
Interrupted: (fiberId: string) => T;
|
|
70
|
+
Die?: (defect: unknown) => T;
|
|
71
|
+
}): T;
|
|
72
|
+
/**
|
|
73
|
+
* Returns the success value or throws
|
|
74
|
+
*/
|
|
75
|
+
orThrow(): A;
|
|
76
|
+
/**
|
|
77
|
+
* Returns the success value, or calls `defaultValue` for any other outcome.
|
|
78
|
+
* The default is lazy: it runs only when the Exit is not a Success.
|
|
79
|
+
*/
|
|
80
|
+
getOrElse(defaultValue: () => A): A;
|
|
81
|
+
/**
|
|
82
|
+
* Converts to Option (Some for Success, None otherwise)
|
|
83
|
+
*/
|
|
84
|
+
toOption(): Option<A>;
|
|
85
|
+
/**
|
|
86
|
+
* Converts to Either (Right for Success, Left for Failure)
|
|
87
|
+
* Throws if Interrupted
|
|
88
|
+
*
|
|
89
|
+
* A `Die` becomes `Left(defect)`, which widens the Left beyond `E`. (`IO.run()` rejects on a
|
|
90
|
+
* `Die` instead, so its Left stays an `E`.) Use {@link isDie} first if the distinction matters.
|
|
91
|
+
*/
|
|
92
|
+
toEither(): Either<E, A>;
|
|
93
|
+
/**
|
|
94
|
+
* Returns the raw value for inspection
|
|
95
|
+
*/
|
|
96
|
+
toValue(): {
|
|
97
|
+
_tag: ExitTag;
|
|
98
|
+
value?: A;
|
|
99
|
+
error?: E;
|
|
100
|
+
defect?: unknown;
|
|
101
|
+
fiberId?: string;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* String representation
|
|
105
|
+
*/
|
|
106
|
+
toString(): string;
|
|
107
|
+
/**
|
|
108
|
+
* JSON serialization
|
|
109
|
+
*/
|
|
110
|
+
toJSON(): {
|
|
111
|
+
_tag: ExitTag;
|
|
112
|
+
value?: A;
|
|
113
|
+
error?: E;
|
|
114
|
+
defect?: unknown;
|
|
115
|
+
fiberId?: string;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/** The effect completed with a value. */
|
|
119
|
+
export interface SuccessExitOf<E extends Type, A extends Type> extends ExitBase<E, A> {
|
|
120
|
+
readonly _tag: "Success";
|
|
121
|
+
readonly value: A;
|
|
122
|
+
}
|
|
123
|
+
/** The effect failed with a typed error, a value from the declared `E` channel. */
|
|
124
|
+
export interface FailureExitOf<E extends Type, A extends Type> extends ExitBase<E, A> {
|
|
125
|
+
readonly _tag: "Failure";
|
|
126
|
+
readonly error: E;
|
|
127
|
+
}
|
|
128
|
+
/** The effect produced a defect: a value that is not an `E`. */
|
|
129
|
+
export interface DieExitOf<E extends Type, A extends Type> extends ExitBase<E, A> {
|
|
130
|
+
readonly _tag: "Die";
|
|
131
|
+
readonly defect: unknown;
|
|
132
|
+
}
|
|
133
|
+
/** The effect was cancelled. */
|
|
134
|
+
export interface InterruptedExitOf<E extends Type, A extends Type> extends ExitBase<E, A> {
|
|
135
|
+
readonly _tag: "Interrupted";
|
|
136
|
+
readonly fiberId: string;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Exit represents the outcome of running an IO effect.
|
|
140
|
+
* - Success: The effect completed successfully with a value
|
|
141
|
+
* - Failure: The effect failed with a typed error — a value from the declared `E` channel
|
|
142
|
+
* - Die: The effect produced a *defect* — a value that is **not** an `E`
|
|
143
|
+
* - Interrupted: The effect was cancelled/interrupted
|
|
144
|
+
*
|
|
145
|
+
* `Die` exists so the error channel stops lying. `IO.sync` and `IO.die` declare
|
|
146
|
+
* `E = never`, so nothing they put in the error channel can be an `E`: a throwing
|
|
147
|
+
* `IO.sync` thunk, a throwing `map`/`flatMap`/`mapError` callback, and `IO.die` all
|
|
148
|
+
* produce values the declared type says cannot exist. Before `Die` these collapsed
|
|
149
|
+
* into `Failure`, so a consumer that pattern-matched on `error._tag` got `undefined`
|
|
150
|
+
* with no runtime signal that anything was wrong.
|
|
151
|
+
*
|
|
152
|
+
* Defects remain **recoverable** — `recover` / `recoverWith` / `fold` / `mapError`
|
|
153
|
+
* treat `Die` exactly as they treat `Failure`. That is deliberate, and it is where
|
|
154
|
+
* functype parts company with ZIO: promoting defects to uncatchable would silently
|
|
155
|
+
* change what every existing `.recover()` catches. `Die` is an *observability* fix,
|
|
156
|
+
* not a control-flow one — it records what the outcome really was when nothing
|
|
157
|
+
* recovered it.
|
|
158
|
+
*
|
|
159
|
+
* `run()` and `runSync()` return `Either<E, A>`, which has no branch for a defect, so they
|
|
160
|
+
* throw it instead. `Die` is observable through `runExit()` and through the `Exit` handed
|
|
161
|
+
* to a `bracketExit` release.
|
|
162
|
+
*
|
|
163
|
+
* `Exit` is a discriminated union of {@link SuccessExitOf}, {@link FailureExitOf},
|
|
164
|
+
* {@link DieExitOf} and {@link InterruptedExitOf}. Each variant holds its own field (`value`,
|
|
165
|
+
* `error`, `defect`, `fiberId`), and the guards narrow to it, so `exit.isSuccess() && exit.value`
|
|
166
|
+
* reads the value. The methods live on {@link ExitBase}, shared through one prototype per variant.
|
|
167
|
+
* Variance comes from the variants, because a union type alias can't carry its own annotation.
|
|
168
|
+
*/
|
|
169
|
+
export type Exit<E extends Type, A extends Type> = SuccessExitOf<E, A> | FailureExitOf<E, A> | DieExitOf<E, A> | InterruptedExitOf<E, A>;
|
|
170
|
+
/**
|
|
171
|
+
* Exit constructor - creates an Exit from a value (defaults to Success)
|
|
172
|
+
*/
|
|
173
|
+
declare const ExitConstructor: <E extends Type, A extends Type>(value: A) => Exit<E, A>;
|
|
174
|
+
declare const ExitStatics: {
|
|
175
|
+
/**
|
|
176
|
+
* Creates a Success Exit
|
|
177
|
+
*/
|
|
178
|
+
succeed: <E extends Type, A extends Type>(value: A) => Exit<E, A>;
|
|
179
|
+
/**
|
|
180
|
+
* Creates a Failure Exit
|
|
181
|
+
*/
|
|
182
|
+
fail: <E extends Type, A extends Type>(error: E) => Exit<E, A>;
|
|
183
|
+
/**
|
|
184
|
+
* Creates a Die Exit carrying a defect — a value that is not an `E`
|
|
185
|
+
*/
|
|
186
|
+
die: <E extends Type, A extends Type>(defect: unknown) => Exit<E, A>;
|
|
187
|
+
/**
|
|
188
|
+
* Creates an Interrupted Exit with a fiber ID
|
|
189
|
+
*/
|
|
190
|
+
interrupt: <E extends Type, A extends Type>(fiberId: string) => Exit<E, A>;
|
|
191
|
+
/**
|
|
192
|
+
* Creates an Interrupted Exit with a default fiber ID
|
|
193
|
+
*/
|
|
194
|
+
interrupted: <E extends Type, A extends Type>() => Exit<E, A>;
|
|
195
|
+
/**
|
|
196
|
+
* Type guard for Success
|
|
197
|
+
*/
|
|
198
|
+
isSuccess: <E extends Type, A extends Type>(exit: Exit<E, A>) => exit is SuccessExitOf<E, A>;
|
|
199
|
+
/**
|
|
200
|
+
* Type guard for Failure
|
|
201
|
+
*/
|
|
202
|
+
isFailure: <E extends Type, A extends Type>(exit: Exit<E, A>) => exit is FailureExitOf<E, A>;
|
|
203
|
+
/**
|
|
204
|
+
* Type guard for Die
|
|
205
|
+
*/
|
|
206
|
+
isDie: <E extends Type, A extends Type>(exit: Exit<E, A>) => exit is DieExitOf<E, A>;
|
|
207
|
+
/**
|
|
208
|
+
* Type guard for Interrupted
|
|
209
|
+
*/
|
|
210
|
+
isInterrupted: <E extends Type, A extends Type>(exit: Exit<E, A>) => exit is InterruptedExitOf<E, A>;
|
|
211
|
+
/**
|
|
212
|
+
* Creates an Exit from an Either
|
|
213
|
+
*/
|
|
214
|
+
fromEither: <E extends Type, A extends Type>(either: Either<E, A>) => Exit<E, A>;
|
|
215
|
+
/**
|
|
216
|
+
* Creates an Exit from an Option
|
|
217
|
+
*/
|
|
218
|
+
fromOption: <A extends Type>(option: Option<A>, onNone: () => unknown) => Exit<unknown, A>;
|
|
219
|
+
/**
|
|
220
|
+
* Combines two Exits, keeping the first failure or combining successes
|
|
221
|
+
*/
|
|
222
|
+
zip: <E extends Type, A extends Type, B extends Type>(exitA: Exit<E, A>, exitB: Exit<E, B>) => Exit<E, readonly [A, B]>;
|
|
223
|
+
/**
|
|
224
|
+
* Collects all Exits into an Exit of array
|
|
225
|
+
*/
|
|
226
|
+
all: <E extends Type, A extends Type>(exits: readonly Exit<E, A>[]) => Exit<E, readonly A[]>;
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* Exit type for representing effect outcomes.
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```typescript
|
|
233
|
+
* const success = Exit.succeed(42)
|
|
234
|
+
* const failure = Exit.fail(new Error("oops"))
|
|
235
|
+
* const interrupted = Exit.interrupt("fiber-123")
|
|
236
|
+
*
|
|
237
|
+
* success.fold(
|
|
238
|
+
* (err) => console.error(err),
|
|
239
|
+
* (value) => console.log(value),
|
|
240
|
+
* (fiberId) => console.log("interrupted:", fiberId)
|
|
241
|
+
* )
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
export declare const Exit: ExitCompanion;
|
|
245
|
+
/** The type of `Exit`: its constructor and its statics, named so that errors and hovers print `ExitCompanion`. */
|
|
246
|
+
export interface ExitCompanion extends ExitConstructorType, ExitStaticsType {}
|
|
247
|
+
type ExitConstructorType = typeof ExitConstructor;
|
|
248
|
+
type ExitStaticsType = typeof ExitStatics;
|
|
249
|
+
export {};
|
package/dist/io/Exit.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Companion as e}from"../companion/Companion.js";import{Left as t,Right as n}from"../either/index.js";import{define as r}from"../internal/define.js";import{safeStringify as i}from"../internal/stringify.js";import{None as a,Some as o}from"../option/index.js";const s=e=>/* @__PURE__ */ Error(`Effect was interrupted: ${e}`),c=r()(`Success`,{[Symbol.toStringTag]:`Exit`,isSuccess(){return!0},isFailure(){return!1},isDie(){return!1},isInterrupted(){return!1},map(e){return f(e(this.value))},mapError(){return f(this.value)},mapBoth(e,t){return f(t(this.value))},flatMap(e){return e(this.value)},fold(e,t){return t(this.value)},match(e){return e.Success(this.value)},orThrow(){return this.value},getOrElse(){return this.value},toOption(){return o(this.value)},toEither(){return n(this.value)},toValue(){return{_tag:`Success`,value:this.value}},toString(){return`Exit.Success(${i(this.value)})`},toJSON(){return{_tag:`Success`,value:this.value}}}),l=r()(`Failure`,{[Symbol.toStringTag]:`Exit`,isSuccess(){return!1},isFailure(){return!0},isDie(){return!1},isInterrupted(){return!1},map(){return p(this.error)},mapError(e){return p(e(this.error))},mapBoth(e){return p(e(this.error))},flatMap(){return p(this.error)},fold(e){return e(this.error)},match(e){return e.Failure(this.error)},orThrow(){throw this.error},getOrElse(e){return e()},toOption(){return a()},toEither(){return t(this.error)},toValue(){return{_tag:`Failure`,error:this.error}},toString(){return`Exit.Failure(${i(this.error)})`},toJSON(){return{_tag:`Failure`,error:this.error}}}),u=r()(`Die`,{[Symbol.toStringTag]:`Exit`,isSuccess(){return!1},isFailure(){return!1},isDie(){return!0},isInterrupted(){return!1},map(){return m(this.defect)},mapError(){return m(this.defect)},mapBoth(){return m(this.defect)},flatMap(){return m(this.defect)},fold(e,t,n,r){return r?r(this.defect):e(this.defect)},match(e){return e.Die?e.Die(this.defect):e.Failure(this.defect)},orThrow(){throw this.defect},getOrElse(e){return e()},toOption(){return a()},toEither(){return t(this.defect)},toValue(){return{_tag:`Die`,defect:this.defect}},toString(){return`Exit.Die(${i(this.defect)})`},toJSON(){return{_tag:`Die`,defect:this.defect}}}),d=r()(`Interrupted`,{[Symbol.toStringTag]:`Exit`,isSuccess(){return!1},isFailure(){return!1},isDie(){return!1},isInterrupted(){return!0},map(){return h(this.fiberId)},mapError(){return h(this.fiberId)},mapBoth(){return h(this.fiberId)},flatMap(){return h(this.fiberId)},fold(e,t,n){if(n)return n(this.fiberId);throw s(this.fiberId)},match(e){return e.Interrupted(this.fiberId)},orThrow(){throw s(this.fiberId)},getOrElse(e){return e()},toOption(){return a()},toEither(){throw Error(`Cannot convert Interrupted Exit to Either: ${this.fiberId}`)},toValue(){return{_tag:`Interrupted`,fiberId:this.fiberId}},toString(){return`Exit.Interrupted(${this.fiberId})`},toJSON(){return{_tag:`Interrupted`,fiberId:this.fiberId}}}),f=e=>{let t=Object.create(c);return t._tag=`Success`,t.value=e,t},p=e=>{let t=Object.create(l);return t._tag=`Failure`,t.error=e,t},m=e=>{let t=Object.create(u);return t._tag=`Die`,t.defect=e,t},h=e=>{let t=Object.create(d);return t._tag=`Interrupted`,t.fiberId=e,t},g=e(e=>f(e),{succeed:e=>f(e),fail:e=>p(e),die:e=>m(e),interrupt:e=>h(e),interrupted:()=>h(`interrupted`),isSuccess:e=>e.isSuccess(),isFailure:e=>e.isFailure(),isDie:e=>e.isDie(),isInterrupted:e=>e.isInterrupted(),fromEither:e=>e.isRight()?f(e.value):p(e.value),fromOption:(e,t)=>e.isSome()?f(e.value):p(t()),zip:(e,t)=>e.isInterrupted()?e:t.isInterrupted()?t:e.isDie()?e:t.isDie()?t:e.isFailure()?e:t.isFailure()?t:f([e.orThrow(),t.orThrow()]),all:e=>{let t=[];for(let n of e){if(n.isInterrupted()||n.isDie()||n.isFailure())return n;t.push(n.orThrow())}return f(t)}});export{g as Exit};
|