<A, E, X1, X2>(options: {
readonly onSuccess: (a: NoInfer<A>) => X1
readonly onFailure: (cause: Cause.Cause<NoInfer<E>>) => X2
}): (self: Exit<A, E>) => X1 | X2
<A, E, X1, X2>(
self: Exit<A, E>,
options: {
readonly onSuccess: (a: A) => X1
readonly onFailure: (cause: Cause.Cause<E>) => X2
}
): X1 | X2Pattern matches on an Exit, handling both success and failure cases.
When to use
Use when you need exhaustive handling of both Exit success and failure
outcomes.
Details
Calls onSuccess with the value if the Exit is a Success, and calls
onFailure with the Cause if the Exit is a Failure.
Example (Matching on an Exit)
import { Exit } from "effect"
const success = Exit.succeed(42)
const result = Exit.match(success, {
onSuccess: (value) => `Got: ${value}`,
onFailure: () => "Failed"
})
console.log(result) // "Got: 42"export const const match: {
<A, E, X1, X2>(options: {
readonly onSuccess: (a: NoInfer<A>) => X1
readonly onFailure: (
cause: Cause.Cause<NoInfer<E>>
) => X2
}): (self: Exit<A, E>) => X1 | X2
<A, E, X1, X2>(
self: Exit<A, E>,
options: {
readonly onSuccess: (a: A) => X1
readonly onFailure: (
cause: Cause.Cause<E>
) => X2
}
): X1 | X2
}
Pattern matches on an Exit, handling both success and failure cases.
When to use
Use when you need exhaustive handling of both Exit success and failure
outcomes.
Details
Calls onSuccess with the value if the Exit is a Success, and calls
onFailure with the Cause if the Exit is a Failure.
Example (Matching on an Exit)
import { Exit } from "effect"
const success = Exit.succeed(42)
const result = Exit.match(success, {
onSuccess: (value) => `Got: ${value}`,
onFailure: () => "Failed"
})
console.log(result) // "Got: 42"
match: {
<function (type parameter) A in <A, E, X1, X2>(options: {
readonly onSuccess: (a: NoInfer<A>) => X1;
readonly onFailure: (cause: Cause.Cause<NoInfer<E>>) => X2;
}): (self: Exit<A, E>) => X1 | X2
A, function (type parameter) E in <A, E, X1, X2>(options: {
readonly onSuccess: (a: NoInfer<A>) => X1;
readonly onFailure: (cause: Cause.Cause<NoInfer<E>>) => X2;
}): (self: Exit<A, E>) => X1 | X2
E, function (type parameter) X1 in <A, E, X1, X2>(options: {
readonly onSuccess: (a: NoInfer<A>) => X1;
readonly onFailure: (cause: Cause.Cause<NoInfer<E>>) => X2;
}): (self: Exit<A, E>) => X1 | X2
X1, function (type parameter) X2 in <A, E, X1, X2>(options: {
readonly onSuccess: (a: NoInfer<A>) => X1;
readonly onFailure: (cause: Cause.Cause<NoInfer<E>>) => X2;
}): (self: Exit<A, E>) => X1 | X2
X2>(options: {
readonly onSuccess: (a: NoInfer<A>) => X1
readonly onFailure: (
cause: Cause.Cause<NoInfer<E>>
) => X2
}
options: {
readonly onSuccess: (a: NoInfer<A>) => X1onSuccess: (a: NoInfer<A>a: type NoInfer<A> = [A][A extends any ? 0 : never]Prevents TypeScript from inferring a type parameter from a specific
position.
When to use
Use when a function parameter must match an inferred type without becoming
an inference source.
Details
The parameter using NoInfer must still match the inferred type.
Example (Controlling inference)
import type { Types } from "effect"
declare function withDefault<T>(value: T, fallback: Types.NoInfer<T>): T
// T is inferred as "a" | "b" from the first argument only
const result = withDefault<"a" | "b">("a", "b")
NoInfer<function (type parameter) A in <A, E, X1, X2>(options: {
readonly onSuccess: (a: NoInfer<A>) => X1;
readonly onFailure: (cause: Cause.Cause<NoInfer<E>>) => X2;
}): (self: Exit<A, E>) => X1 | X2
A>) => function (type parameter) X1 in <A, E, X1, X2>(options: {
readonly onSuccess: (a: NoInfer<A>) => X1;
readonly onFailure: (cause: Cause.Cause<NoInfer<E>>) => X2;
}): (self: Exit<A, E>) => X1 | X2
X1
readonly onFailure: (cause: Cause.Cause<NoInfer<E>>) => X2onFailure: (cause: Cause.Cause<NoInfer<E>>(parameter) cause: {
reasons: ReadonlyArray<Reason<E>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
cause: import CauseCause.type Cause.Cause = /*unresolved*/ anyCause<type NoInfer<A> = [A][A extends any ? 0 : never]Prevents TypeScript from inferring a type parameter from a specific
position.
When to use
Use when a function parameter must match an inferred type without becoming
an inference source.
Details
The parameter using NoInfer must still match the inferred type.
Example (Controlling inference)
import type { Types } from "effect"
declare function withDefault<T>(value: T, fallback: Types.NoInfer<T>): T
// T is inferred as "a" | "b" from the first argument only
const result = withDefault<"a" | "b">("a", "b")
NoInfer<function (type parameter) E in <A, E, X1, X2>(options: {
readonly onSuccess: (a: NoInfer<A>) => X1;
readonly onFailure: (cause: Cause.Cause<NoInfer<E>>) => X2;
}): (self: Exit<A, E>) => X1 | X2
E>>) => function (type parameter) X2 in <A, E, X1, X2>(options: {
readonly onSuccess: (a: NoInfer<A>) => X1;
readonly onFailure: (cause: Cause.Cause<NoInfer<E>>) => X2;
}): (self: Exit<A, E>) => X1 | X2
X2
}): (self: Exit<A, E>self: type Exit<A, E = never> = Success<A, E> | Failure<A, E>Represents the result of an Effect computation.
When to use
Use when you need to synchronously inspect whether an Effect computation
succeeded or failed.
Details
An Exit<A, E> is either Success<A, E> containing a value of type A, or
Failure<A, E> containing a Cause<E> describing why the computation
failed.
Since Exit is also an Effect, you can yield it inside Effect.gen.
Example (Pattern matching on an Exit)
import { Exit } from "effect"
const success: Exit.Exit<number> = Exit.succeed(42)
const failure: Exit.Exit<number, string> = Exit.fail("error")
const result = Exit.match(success, {
onSuccess: (value) => `Got value: ${value}`,
onFailure: (cause) => `Got error: ${cause}`
})
Namespace containing helper types shared by Exit values.
When to use
Use to reference helper types that describe the shared structure of Exit
values.
Exit<function (type parameter) A in <A, E, X1, X2>(options: {
readonly onSuccess: (a: NoInfer<A>) => X1;
readonly onFailure: (cause: Cause.Cause<NoInfer<E>>) => X2;
}): (self: Exit<A, E>) => X1 | X2
A, function (type parameter) E in <A, E, X1, X2>(options: {
readonly onSuccess: (a: NoInfer<A>) => X1;
readonly onFailure: (cause: Cause.Cause<NoInfer<E>>) => X2;
}): (self: Exit<A, E>) => X1 | X2
E>) => function (type parameter) X1 in <A, E, X1, X2>(options: {
readonly onSuccess: (a: NoInfer<A>) => X1;
readonly onFailure: (cause: Cause.Cause<NoInfer<E>>) => X2;
}): (self: Exit<A, E>) => X1 | X2
X1 | function (type parameter) X2 in <A, E, X1, X2>(options: {
readonly onSuccess: (a: NoInfer<A>) => X1;
readonly onFailure: (cause: Cause.Cause<NoInfer<E>>) => X2;
}): (self: Exit<A, E>) => X1 | X2
X2
<function (type parameter) A in <A, E, X1, X2>(self: Exit<A, E>, options: {
readonly onSuccess: (a: A) => X1;
readonly onFailure: (cause: Cause.Cause<E>) => X2;
}): X1 | X2
A, function (type parameter) E in <A, E, X1, X2>(self: Exit<A, E>, options: {
readonly onSuccess: (a: A) => X1;
readonly onFailure: (cause: Cause.Cause<E>) => X2;
}): X1 | X2
E, function (type parameter) X1 in <A, E, X1, X2>(self: Exit<A, E>, options: {
readonly onSuccess: (a: A) => X1;
readonly onFailure: (cause: Cause.Cause<E>) => X2;
}): X1 | X2
X1, function (type parameter) X2 in <A, E, X1, X2>(self: Exit<A, E>, options: {
readonly onSuccess: (a: A) => X1;
readonly onFailure: (cause: Cause.Cause<E>) => X2;
}): X1 | X2
X2>(
self: Exit<A, E>self: type Exit<A, E = never> = Success<A, E> | Failure<A, E>Represents the result of an Effect computation.
When to use
Use when you need to synchronously inspect whether an Effect computation
succeeded or failed.
Details
An Exit<A, E> is either Success<A, E> containing a value of type A, or
Failure<A, E> containing a Cause<E> describing why the computation
failed.
Since Exit is also an Effect, you can yield it inside Effect.gen.
Example (Pattern matching on an Exit)
import { Exit } from "effect"
const success: Exit.Exit<number> = Exit.succeed(42)
const failure: Exit.Exit<number, string> = Exit.fail("error")
const result = Exit.match(success, {
onSuccess: (value) => `Got value: ${value}`,
onFailure: (cause) => `Got error: ${cause}`
})
Namespace containing helper types shared by Exit values.
When to use
Use to reference helper types that describe the shared structure of Exit
values.
Exit<function (type parameter) A in <A, E, X1, X2>(self: Exit<A, E>, options: {
readonly onSuccess: (a: A) => X1;
readonly onFailure: (cause: Cause.Cause<E>) => X2;
}): X1 | X2
A, function (type parameter) E in <A, E, X1, X2>(self: Exit<A, E>, options: {
readonly onSuccess: (a: A) => X1;
readonly onFailure: (cause: Cause.Cause<E>) => X2;
}): X1 | X2
E>,
options: {
readonly onSuccess: (a: A) => X1
readonly onFailure: (
cause: Cause.Cause<E>
) => X2
}
options: {
readonly onSuccess: (a: A) => X1onSuccess: (a: Aa: function (type parameter) A in <A, E, X1, X2>(self: Exit<A, E>, options: {
readonly onSuccess: (a: A) => X1;
readonly onFailure: (cause: Cause.Cause<E>) => X2;
}): X1 | X2
A) => function (type parameter) X1 in <A, E, X1, X2>(self: Exit<A, E>, options: {
readonly onSuccess: (a: A) => X1;
readonly onFailure: (cause: Cause.Cause<E>) => X2;
}): X1 | X2
X1
readonly onFailure: (cause: Cause.Cause<E>) => X2onFailure: (cause: Cause.Cause<E>(parameter) cause: {
reasons: ReadonlyArray<Reason<E>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
cause: import CauseCause.type Cause.Cause = /*unresolved*/ anyCause<function (type parameter) E in <A, E, X1, X2>(self: Exit<A, E>, options: {
readonly onSuccess: (a: A) => X1;
readonly onFailure: (cause: Cause.Cause<E>) => X2;
}): X1 | X2
E>) => function (type parameter) X2 in <A, E, X1, X2>(self: Exit<A, E>, options: {
readonly onSuccess: (a: A) => X1;
readonly onFailure: (cause: Cause.Cause<E>) => X2;
}): X1 | X2
X2
}
): function (type parameter) X1 in <A, E, X1, X2>(self: Exit<A, E>, options: {
readonly onSuccess: (a: A) => X1;
readonly onFailure: (cause: Cause.Cause<E>) => X2;
}): X1 | X2
X1 | function (type parameter) X2 in <A, E, X1, X2>(self: Exit<A, E>, options: {
readonly onSuccess: (a: A) => X1;
readonly onFailure: (cause: Cause.Cause<E>) => X2;
}): X1 | X2
X2
} = import effecteffect.const exitMatch: {
<A, E, X1, X2>(options: {
readonly onSuccess: (a: NoInfer<A>) => X1
readonly onFailure: (
cause: Cause.Cause<NoInfer<E>>
) => X2
}): (self: Exit.Exit<A, E>) => X1 | X2
<A, E, X1, X2>(
self: Exit.Exit<A, E>,
options: {
readonly onSuccess: (a: A) => X1
readonly onFailure: (
cause: Cause.Cause<E>
) => X2
}
): X1 | X2
}
exitMatch