<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.
When to use
Use when you need to fold an Effect into a value by handling success and
failure differently without triggering side effects.
Details
match lets you define custom handlers for both success and failure
scenarios. You provide separate functions to handle each case, allowing you
to process the result if the effect succeeds, or handle the error if the
effect fails.
Example (Matching success and failure values)
import { Data, Effect } from "effect"
class ExampleError extends Data.TaggedError("ExampleError")<{ readonly message: string }> {}
const success: Effect.Effect<number, ExampleError> = Effect.succeed(42)
const program1 = Effect.match(success, {
onFailure: (error) => `failure: ${error.message}`,
onSuccess: (value) => `success: ${value}`
})
// Run and log the result of the successful effect
Effect.runPromise(program1).then(console.log)
// Output: "success: 42"
const failure: Effect.Effect<number, ExampleError> = Effect.fail(
new ExampleError({ message: "Uh oh!" })
)
const program2 = Effect.match(failure, {
onFailure: (error) => `failure: ${error.message}`,
onSuccess: (value) => `success: ${value}`
})
// Run and log the result of the failed effect
Effect.runPromise(program2).then(console.log)
// Output: "failure: Uh oh!"export const const match: {
<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.
When to use
Use when you need to fold an Effect into a value by handling success and
failure differently without triggering side effects.
Details
match lets you define custom handlers for both success and failure
scenarios. You provide separate functions to handle each case, allowing you
to process the result if the effect succeeds, or handle the error if the
effect fails.
Example (Matching success and failure values)
import { Data, Effect } from "effect"
class ExampleError extends Data.TaggedError("ExampleError")<{ readonly message: string }> {}
const success: Effect.Effect<number, ExampleError> = Effect.succeed(42)
const program1 = Effect.match(success, {
onFailure: (error) => `failure: ${error.message}`,
onSuccess: (value) => `success: ${value}`
})
// Run and log the result of the successful effect
Effect.runPromise(program1).then(console.log)
// Output: "success: 42"
const failure: Effect.Effect<number, ExampleError> = Effect.fail(
new ExampleError({ message: "Uh oh!" })
)
const program2 = Effect.match(failure, {
onFailure: (error) => `failure: ${error.message}`,
onSuccess: (value) => `success: ${value}`
})
// Run and log the result of the failed effect
Effect.runPromise(program2).then(console.log)
// Output: "failure: Uh oh!"
match: {
<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 match: {
<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>
}
match