<E, A2, A, A3>(options: {
readonly onFailure: (error: 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: (error: E) => A2
readonly onSuccess: (value: A) => A3
}
): Effect<A2 | A3, never, R>Handles both success and failure cases of an effect without performing side effects, with eager evaluation for resolved effects.
When to use
Use when you need to handle both success and failure cases of an
already-resolved Effect with optimized handling.
Details
matchEager works like match but provides better performance for resolved
effects (Success or Failure). When the effect is already resolved, it applies
the handlers immediately without fiber scheduling. For unresolved effects,
it falls back to the regular match behavior.
Example (Pattern matching eagerly when possible)
import { Effect } from "effect"
const program = Effect.gen(function*() {
const result = yield* Effect.matchEager(Effect.succeed(42), {
onFailure: (error) => `Failed: ${error}`,
onSuccess: (value) => `Success: ${value}`
})
console.log(result) // "Success: 42"
})export const const matchEager: {
<E, A2, A, A3>(options: {
readonly onFailure: (error: 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: (error: E) => A2
readonly onSuccess: (value: A) => A3
}
): Effect<A2 | A3, never, R>
}
Handles both success and failure cases of an effect without performing side
effects, with eager evaluation for resolved effects.
When to use
Use when you need to handle both success and failure cases of an
already-resolved Effect with optimized handling.
Details
matchEager works like match but provides better performance for resolved
effects (Success or Failure). When the effect is already resolved, it applies
the handlers immediately without fiber scheduling. For unresolved effects,
it falls back to the regular match behavior.
Example (Pattern matching eagerly when possible)
import { Effect } from "effect"
const program = Effect.gen(function*() {
const result = yield* Effect.matchEager(Effect.succeed(42), {
onFailure: (error) => `Failed: ${error}`,
onSuccess: (value) => `Success: ${value}`
})
console.log(result) // "Success: 42"
})
matchEager: {
<function (type parameter) E in <E, A2, A, A3>(options: {
readonly onFailure: (error: 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: (error: 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: (error: 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: (error: E) => A2;
readonly onSuccess: (value: A) => A3;
}): <R>(self: Effect<A, E, R>) => Effect<A2 | A3, never, R>
A3>(options: {
readonly onFailure: (error: E) => A2
readonly onSuccess: (value: A) => A3
}
options: {
readonly onFailure: (error: E) => A2onFailure: (error: Eerror: function (type parameter) E in <E, A2, A, A3>(options: {
readonly onFailure: (error: 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: (error: 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: (error: 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: (error: 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: (error: 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: (error: 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: (error: 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: (error: 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: (error: 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: (error: 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: (error: 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: (error: 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: (error: 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: (error: 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: (error: 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: (error: E) => A2;
readonly onSuccess: (value: A) => A3;
}): Effect<A2 | A3, never, R>
R>,
options: {
readonly onFailure: (error: E) => A2
readonly onSuccess: (value: A) => A3
}
options: {
readonly onFailure: (error: E) => A2onFailure: (error: Eerror: function (type parameter) E in <A, E, R, A2, A3>(self: Effect<A, E, R>, options: {
readonly onFailure: (error: 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: (error: 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: (error: 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: (error: 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: (error: 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: (error: 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: (error: E) => A2;
readonly onSuccess: (value: A) => A3;
}): Effect<A2 | A3, never, R>
R>
} = import internalinternal.const matchEager: {
<E, A2, A, A3>(options: {
readonly onFailure: (error: 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: (error: E) => A2
readonly onSuccess: (value: A) => A3
}
): Effect.Effect<A2 | A3, never, R>
}
matchEager