<E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>
readonly onSuccess: (a: A) => Effect<A3, E3, R3>
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
<A, E, R, A2, E2, R2, A3, E3, R3>(
self: Effect<A, E, R>,
options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>
readonly onSuccess: (a: A) => Effect<A3, E3, R3>
}
): Effect<A2 | A3, E2 | E3, R2 | R3 | R>Handles failures with access to the cause and allows performing side effects.
When to use
Use when you need to fold an Effect with effectful success handlers and
Cause-aware failure handlers.
Details
The matchCauseEffect function works similarly to matchCause, but it
also allows you to perform additional side effects based on the failure
cause. This function provides access to the complete cause of the failure,
making it possible to differentiate between various failure types, and allows
you to respond accordingly while performing side effects (like logging or
other operations).
Example (Effectfully matching on causes)
import { Cause, Console, Data, Effect, Result } from "effect"
class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
const task = Effect.fail(new TaskError({ message: "Task failed" }))
const program = Effect.matchCauseEffect(task, {
onFailure: (cause) =>
Effect.gen(function*() {
if (Cause.hasFails(cause)) {
const error = Cause.findError(cause)
if (Result.isSuccess(error)) {
yield* Console.log(`Handling error: ${error.success.message}`)
}
return "recovered from error"
} else {
yield* Console.log("Handling interruption or defect")
return "recovered from interruption/defect"
}
}),
onSuccess: (value) =>
Effect.gen(function*() {
yield* Console.log(`Success: ${value}`)
return `processed ${value}`
})
})
Effect.runPromise(program).then(console.log)
// Output:
// Handling error: Task failed
// recovered from errorexport const const matchCauseEffect: {
<E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (
cause: Cause.Cause<E>
) => Effect<A2, E2, R2>
readonly onSuccess: (
a: A
) => Effect<A3, E3, R3>
}): <R>(
self: Effect<A, E, R>
) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
<A, E, R, A2, E2, R2, A3, E3, R3>(
self: Effect<A, E, R>,
options: {
readonly onFailure: (
cause: Cause.Cause<E>
) => Effect<A2, E2, R2>
readonly onSuccess: (
a: A
) => Effect<A3, E3, R3>
}
): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
}
Handles failures with access to the cause and allows performing side effects.
When to use
Use when you need to fold an Effect with effectful success handlers and
Cause-aware failure handlers.
Details
The matchCauseEffect function works similarly to
matchCause
, but it
also allows you to perform additional side effects based on the failure
cause. This function provides access to the complete cause of the failure,
making it possible to differentiate between various failure types, and allows
you to respond accordingly while performing side effects (like logging or
other operations).
Example (Effectfully matching on causes)
import { Cause, Console, Data, Effect, Result } from "effect"
class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
const task = Effect.fail(new TaskError({ message: "Task failed" }))
const program = Effect.matchCauseEffect(task, {
onFailure: (cause) =>
Effect.gen(function*() {
if (Cause.hasFails(cause)) {
const error = Cause.findError(cause)
if (Result.isSuccess(error)) {
yield* Console.log(`Handling error: ${error.success.message}`)
}
return "recovered from error"
} else {
yield* Console.log("Handling interruption or defect")
return "recovered from interruption/defect"
}
}),
onSuccess: (value) =>
Effect.gen(function*() {
yield* Console.log(`Success: ${value}`)
return `processed ${value}`
})
})
Effect.runPromise(program).then(console.log)
// Output:
// Handling error: Task failed
// recovered from error
matchCauseEffect: {
<function (type parameter) E in <E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
E, function (type parameter) A2 in <E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
A2, function (type parameter) E2 in <E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
E2, function (type parameter) R2 in <E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
R2, function (type parameter) A in <E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
A, function (type parameter) A3 in <E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
A3, function (type parameter) E3 in <E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
E3, function (type parameter) R3 in <E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
R3>(options: {
readonly onFailure: (
cause: Cause.Cause<E>
) => Effect<A2, E2, R2>
readonly onSuccess: (a: A) => Effect<A3, E3, R3>
}
options: {
readonly onFailure: (
cause: Cause.Cause<E>
) => Effect<A2, E2, R2>
onFailure: (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.interface Cause<out E>A structured representation of how an Effect failed.
When to use
Use to preserve the full structured failure information for an effect instead
of collapsing it to a single error value.
Details
Access the individual failure entries through the reasons array, then
narrow each entry with
isFailReason
,
isDieReason
, or
- Use
hasFails
/
hasDies
/
hasInterrupts
to test
for the presence of specific reason kinds without iterating.
- Use
findError
/
findDefect
to extract the first value
of a given kind.
- Use
combine
to merge two causes.
Cause implements Equal — two causes with the same reasons (by value)
compare as equal.
Example (Creating and inspecting a cause)
import { Cause } from "effect"
const cause = Cause.fail("Something went wrong")
console.log(cause.reasons.length) // 1
console.log(Cause.isFailReason(cause.reasons[0])) // true
Companion namespace for the Cause interface.
Cause<function (type parameter) E in <E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
E>) => interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<function (type parameter) A2 in <E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
A2, function (type parameter) E2 in <E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
E2, function (type parameter) R2 in <E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
R2>
readonly onSuccess: (a: A) => Effect<A3, E3, R3>onSuccess: (a: Aa: function (type parameter) A in <E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
A) => interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<function (type parameter) A3 in <E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
A3, function (type parameter) E3 in <E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
E3, function (type parameter) R3 in <E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
R3>
}): <function (type parameter) R in <R>(self: Effect<A, E, R>): Effect<A2 | A3, E2 | E3, R2 | R3 | R>R>(self: Effect<A, E, R>(parameter) self: {
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;
}
self: interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<function (type parameter) A in <E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
A, function (type parameter) E in <E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
E, function (type parameter) R in <R>(self: Effect<A, E, R>): Effect<A2 | A3, E2 | E3, R2 | R3 | R>R>) => interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<function (type parameter) A2 in <E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
A2 | function (type parameter) A3 in <E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
A3, function (type parameter) E2 in <E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
E2 | function (type parameter) E3 in <E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
E3, function (type parameter) R2 in <E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
R2 | function (type parameter) R3 in <E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, E2 | E3, R2 | R3 | R>
R3 | function (type parameter) R in <R>(self: Effect<A, E, R>): Effect<A2 | A3, E2 | E3, R2 | R3 | R>R>
<function (type parameter) A in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
A, function (type parameter) E in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
E, function (type parameter) R in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
R, function (type parameter) A2 in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
A2, function (type parameter) E2 in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
E2, function (type parameter) R2 in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
R2, function (type parameter) A3 in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
A3, function (type parameter) E3 in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
E3, function (type parameter) R3 in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
R3>(
self: Effect<A, E, R>(parameter) self: {
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;
}
self: interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<function (type parameter) A in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
A, function (type parameter) E in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
E, function (type parameter) R in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
R>,
options: {
readonly onFailure: (
cause: Cause.Cause<E>
) => Effect<A2, E2, R2>
readonly onSuccess: (a: A) => Effect<A3, E3, R3>
}
options: {
readonly onFailure: (
cause: Cause.Cause<E>
) => Effect<A2, E2, R2>
onFailure: (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.interface Cause<out E>A structured representation of how an Effect failed.
When to use
Use to preserve the full structured failure information for an effect instead
of collapsing it to a single error value.
Details
Access the individual failure entries through the reasons array, then
narrow each entry with
isFailReason
,
isDieReason
, or
- Use
hasFails
/
hasDies
/
hasInterrupts
to test
for the presence of specific reason kinds without iterating.
- Use
findError
/
findDefect
to extract the first value
of a given kind.
- Use
combine
to merge two causes.
Cause implements Equal — two causes with the same reasons (by value)
compare as equal.
Example (Creating and inspecting a cause)
import { Cause } from "effect"
const cause = Cause.fail("Something went wrong")
console.log(cause.reasons.length) // 1
console.log(Cause.isFailReason(cause.reasons[0])) // true
Companion namespace for the Cause interface.
Cause<function (type parameter) E in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
E>) => interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<function (type parameter) A2 in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
A2, function (type parameter) E2 in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
E2, function (type parameter) R2 in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
R2>
readonly onSuccess: (a: A) => Effect<A3, E3, R3>onSuccess: (a: Aa: function (type parameter) A in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
A) => interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<function (type parameter) A3 in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
A3, function (type parameter) E3 in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
E3, function (type parameter) R3 in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
R3>
}
): interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<function (type parameter) A2 in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
A2 | function (type parameter) A3 in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
A3, function (type parameter) E2 in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
E2 | function (type parameter) E3 in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
E3, function (type parameter) R2 in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
R2 | function (type parameter) R3 in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
R3 | function (type parameter) R in <A, E, R, A2, E2, R2, A3, E3, R3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>;
readonly onSuccess: (a: A) => Effect<A3, E3, R3>;
}): Effect<A2 | A3, E2 | E3, R2 | R3 | R>
R>
} = import internalinternal.const matchCauseEffect: {
<E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (
cause: Cause.Cause<E>
) => Effect.Effect<A2, E2, R2>
readonly onSuccess: (
a: A
) => Effect.Effect<A3, E3, R3>
}): <R>(
self: Effect.Effect<A, E, R>
) => Effect.Effect<
A2 | A3,
E2 | E3,
R2 | R3 | R
>
<A, E, R, A2, E2, R2, A3, E3, R3>(
self: Effect.Effect<A, E, R>,
options: {
readonly onFailure: (
cause: Cause.Cause<E>
) => Effect.Effect<A2, E2, R2>
readonly onSuccess: (
a: A
) => Effect.Effect<A3, E3, R3>
}
): Effect.Effect<A2 | A3, E2 | E3, R2 | R3 | R>
}
matchCauseEffect