<E, A2, A, A3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2
readonly onSuccess: (a: A) => A3
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, never, R>
<A, E, R, A2, A3>(
self: Effect<A, E, R>,
options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2
readonly onSuccess: (a: A) => A3
}
): Effect<A2 | A3, never, R>Handles failures by matching the cause of failure.
When to use
Use when you need to fold an Effect while the failure handler inspects the
full Cause.
Details
The matchCause function allows you to handle failures with access to the
full cause of the failure within a fiber.
Example (Matching on success or failure causes)
import { Cause, Effect } from "effect"
const task = Effect.fail("Something went wrong")
const program = Effect.matchCause(task, {
onFailure: (cause) => `Failed: ${Cause.squash(cause)}`,
onSuccess: (value) => `Success: ${value}`
})
Effect.runPromise(program).then(console.log)
// Output: "Failed: Error: Something went wrong"export const const matchCause: {
<E, A2, A, A3>(options: {
readonly onFailure: (
cause: Cause.Cause<E>
) => A2
readonly onSuccess: (a: A) => A3
}): <R>(
self: Effect<A, E, R>
) => Effect<A2 | A3, never, R>
<A, E, R, A2, A3>(
self: Effect<A, E, R>,
options: {
readonly onFailure: (
cause: Cause.Cause<E>
) => A2
readonly onSuccess: (a: A) => A3
}
): Effect<A2 | A3, never, R>
}
Handles failures by matching the cause of failure.
When to use
Use when you need to fold an Effect while the failure handler inspects the
full Cause.
Details
The matchCause function allows you to handle failures with access to the
full cause of the failure within a fiber.
Example (Matching on success or failure causes)
import { Cause, Effect } from "effect"
const task = Effect.fail("Something went wrong")
const program = Effect.matchCause(task, {
onFailure: (cause) => `Failed: ${Cause.squash(cause)}`,
onSuccess: (value) => `Success: ${value}`
})
Effect.runPromise(program).then(console.log)
// Output: "Failed: Error: Something went wrong"
matchCause: {
<function (type parameter) E in <E, A2, A, A3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, never, R>
E, function (type parameter) A2 in <E, A2, A, A3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, never, R>
A2, function (type parameter) A in <E, A2, A, A3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, never, R>
A, function (type parameter) A3 in <E, A2, A, A3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, never, R>
A3>(options: {
readonly onFailure: (
cause: Cause.Cause<E>
) => A2
readonly onSuccess: (a: A) => A3
}
options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2onFailure: (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 <E, A2, A, A3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, never, R>
E>) => function (type parameter) A2 in <E, A2, A, A3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, never, R>
A2
readonly onSuccess: (a: A) => A3onSuccess: (a: Aa: function (type parameter) A in <E, A2, A, A3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, never, R>
A) => function (type parameter) A3 in <E, A2, A, A3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, never, R>
A3
}): <function (type parameter) R in <R>(self: Effect<A, E, R>): Effect<A2 | A3, never, 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, A, A3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, never, R>
A, function (type parameter) E in <E, A2, A, A3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, never, R>
E, function (type parameter) R in <R>(self: Effect<A, E, R>): Effect<A2 | A3, never, 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, A, A3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, never, R>
A2 | function (type parameter) A3 in <E, A2, A, A3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, never, R>
A3, never, function (type parameter) R in <R>(self: Effect<A, E, R>): Effect<A2 | A3, never, R>R>
<function (type parameter) A in <A, E, R, A2, A3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): Effect<A2 | A3, never, R>
A, function (type parameter) E in <A, E, R, A2, A3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): Effect<A2 | A3, never, R>
E, function (type parameter) R in <A, E, R, A2, A3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): Effect<A2 | A3, never, R>
R, function (type parameter) A2 in <A, E, R, A2, A3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): Effect<A2 | A3, never, R>
A2, function (type parameter) A3 in <A, E, R, A2, A3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): Effect<A2 | A3, never, R>
A3>(
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, A3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): Effect<A2 | A3, never, R>
A, function (type parameter) E in <A, E, R, A2, A3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): Effect<A2 | A3, never, R>
E, function (type parameter) R in <A, E, R, A2, A3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): Effect<A2 | A3, never, R>
R>,
options: {
readonly onFailure: (
cause: Cause.Cause<E>
) => A2
readonly onSuccess: (a: A) => A3
}
options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2onFailure: (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, R, A2, A3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): Effect<A2 | A3, never, R>
E>) => function (type parameter) A2 in <A, E, R, A2, A3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): Effect<A2 | A3, never, R>
A2
readonly onSuccess: (a: A) => A3onSuccess: (a: Aa: function (type parameter) A in <A, E, R, A2, A3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): Effect<A2 | A3, never, R>
A) => function (type parameter) A3 in <A, E, R, A2, A3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): Effect<A2 | A3, never, R>
A3
}
): 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, A3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): Effect<A2 | A3, never, R>
A2 | function (type parameter) A3 in <A, E, R, A2, A3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): Effect<A2 | A3, never, R>
A3, never, function (type parameter) R in <A, E, R, A2, A3>(self: Effect<A, E, R>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (a: A) => A3;
}): Effect<A2 | A3, never, R>
R>
} = import internalinternal.const matchCause: {
<E, A2, A, A3>(options: {
readonly onFailure: (
cause: Cause.Cause<E>
) => A2
readonly onSuccess: (a: A) => A3
}): <R>(
self: Effect.Effect<A, E, R>
) => Effect.Effect<A2 | A3, never, R>
<A, E, R, A2, A3>(
self: Effect.Effect<A, E, R>,
options: {
readonly onFailure: (
cause: Cause.Cause<E>
) => A2
readonly onSuccess: (a: A) => A3
}
): Effect.Effect<A2 | A3, never, R>
}
matchCause