<E, A2, A, A3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2
readonly onSuccess: (value: 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: (value: A) => A3
}
): Effect<A2 | A3, never, R>Handles failures by matching the cause of failure with eager evaluation.
When to use
Use when you expect an Effect to already be resolved and want to match the
Cause without regular effect pipeline overhead.
Details
matchCauseEager works like matchCause but provides better performance for resolved
effects by immediately applying the matching function instead of deferring it
through the effect pipeline.
Example (Eagerly matching already completed effects)
import { Effect } from "effect"
const handleResult = Effect.matchCauseEager(Effect.succeed(42), {
onSuccess: (value) => `Success: ${value}`,
onFailure: (cause) => `Failed: ${cause}`
})export const const matchCauseEager: {
<E, A2, A, A3>(options: {
readonly onFailure: (
cause: Cause.Cause<E>
) => A2
readonly onSuccess: (value: 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: (value: A) => A3
}
): Effect<A2 | A3, never, R>
}
Handles failures by matching the cause of failure with eager evaluation.
When to use
Use when you expect an Effect to already be resolved and want to match the
Cause without regular effect pipeline overhead.
Details
matchCauseEager works like matchCause but provides better performance for resolved
effects by immediately applying the matching function instead of deferring it
through the effect pipeline.
Example (Eagerly matching already completed effects)
import { Effect } from "effect"
const handleResult = Effect.matchCauseEager(Effect.succeed(42), {
onSuccess: (value) => `Success: ${value}`,
onFailure: (cause) => `Failed: ${cause}`
})
matchCauseEager: {
<function (type parameter) E in <E, A2, A, A3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (value: 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: (value: 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: (value: 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: (value: A) => A3;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, never, R>
A3>(options: {
readonly onFailure: (
cause: Cause.Cause<E>
) => A2
readonly onSuccess: (value: 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: (value: 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: (value: A) => A3;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, never, R>
A2
readonly onSuccess: (value: A) => A3onSuccess: (value: Avalue: function (type parameter) A in <E, A2, A, A3>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => A2;
readonly onSuccess: (value: 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: (value: 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: (value: 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: (value: 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: (value: 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: (value: 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: (value: 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: (value: 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: (value: 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: (value: 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: (value: 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: (value: 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: (value: 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: (value: A) => A3;
}): Effect<A2 | A3, never, R>
R>,
options: {
readonly onFailure: (
cause: Cause.Cause<E>
) => A2
readonly onSuccess: (value: 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: (value: 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: (value: A) => A3;
}): Effect<A2 | A3, never, R>
A2
readonly onSuccess: (value: A) => A3onSuccess: (value: Avalue: 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: (value: 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: (value: 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: (value: 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: (value: 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: (value: A) => A3;
}): Effect<A2 | A3, never, R>
R>
} = import internalinternal.const matchCauseEager: {
<E, A2, A, A3>(options: {
readonly onFailure: (
cause: Cause.Cause<E>
) => A2
readonly onSuccess: (value: 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: (value: A) => A3
}
): Effect.Effect<A2 | A3, never, R>
}
matchCauseEager