Play with Exit
Exit represents the result of an effect execution
1
import { exit } from "@matechs/effect"
Copied!
Following the exposed module
1
export const isDone = <E, A>(e: Exit<E, A>): e is Done<A>
2
export const isRaise = <E, A>(e: Exit<E, A>): e is Raise<E>
3
export const isAbort = <E, A>(e: Exit<E, A>): e is Abort
4
export const isInterrupt = <E, A>(e: Exit<E, A>): e is Interrupt
5
6
export function fold<E, A, R>(
7
onDone: (v: A) => R,
8
onRaise: (v: E) => R,
9
onAbort: (v: unknown) => R,
10
onInterrupt: (i: Interrupt) => R
11
): (e: Exit<E, A>) => R
Copied!
The Exit ADT located at @matechs/effect/lib/original/exit:
1
export type Exit<E, A> = Done<A> | Cause<E>;
2
export type ExitTag = Exit<unknown, unknown>["_tag"];
3
4
export interface Done<A> {
5
readonly _tag: "Done";
6
readonly value: A;
7
}
8
9
export function done<A>(v: A): Done<A> {
10
return {
11
_tag: "Done",
12
value: v
13
};
14
}
15
16
export type Cause<E> = Raise<E> | Abort | Interrupt;
17
18
export interface Raise<E> {
19
readonly _tag: "Raise";
20
readonly error: E;
21
}
22
23
export function raise<E>(e: E): Raise<E> {
24
return {
25
_tag: "Raise",
26
error: e
27
};
28
}
29
30
export interface Abort {
31
readonly _tag: "Abort";
32
readonly abortedWith: unknown;
33
}
34
35
export function abort(a: unknown): Abort {
36
return {
37
_tag: "Abort",
38
abortedWith: a
39
};
40
}
41
42
export interface Interrupt {
43
readonly _tag: "Interrupt";
44
readonly error?: Error;
45
readonly others?: Error[];
46
}
47
48
export const interrupt: Interrupt = {
49
_tag: "Interrupt"
50
};
51
52
export const interruptWithError = (err?: Error): Interrupt =>
53
err
54
? {
55
_tag: "Interrupt",
56
error: err
57
}
58
: {
59
_tag: "Interrupt"
60
};
61
62
export const interruptWithErrorAndOthers = (
63
err: Error,
64
others?: Error[]
65
): Interrupt =>
66
others
67
? {
68
_tag: "Interrupt",
69
error: err,
70
others
71
}
72
: {
73
_tag: "Interrupt",
74
error: err
75
};
76
Copied!
Last modified 1yr ago
Copy link