<E, XE, XR>(
predicate: Predicate.Predicate<Cause.Cause<E>>,
f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>
): <A, R>(self: Effect<A, E, R>) => Effect<A, E | XE, R | XR>
<A, E, R, XE, XR>(
self: Effect<A, E, R>,
predicate: Predicate.Predicate<Cause.Cause<E>>,
f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>
): Effect<A, E | XE, R | XR>Runs the finalizer only when this effect fails and the Cause matches the
provided predicate.
Example (Running cleanup for selected failures)
import { Cause, Console, Effect } from "effect"
const task = Effect.fail("boom")
const program = Effect.onErrorIf(
task,
Cause.hasFails,
(cause) =>
Effect.gen(function*() {
yield* Console.log(`Cause: ${Cause.pretty(cause)}`)
})
)export const const onErrorIf: {
<E, XE, XR>(
predicate: Predicate.Predicate<
Cause.Cause<E>
>,
f: (
cause: Cause.Cause<E>
) => Effect<void, XE, XR>
): <A, R>(
self: Effect<A, E, R>
) => Effect<A, E | XE, R | XR>
<A, E, R, XE, XR>(
self: Effect<A, E, R>,
predicate: Predicate.Predicate<
Cause.Cause<E>
>,
f: (
cause: Cause.Cause<E>
) => Effect<void, XE, XR>
): Effect<A, E | XE, R | XR>
}
Runs the finalizer only when this effect fails and the Cause matches the
provided predicate.
Example (Running cleanup for selected failures)
import { Cause, Console, Effect } from "effect"
const task = Effect.fail("boom")
const program = Effect.onErrorIf(
task,
Cause.hasFails,
(cause) =>
Effect.gen(function*() {
yield* Console.log(`Cause: ${Cause.pretty(cause)}`)
})
)
onErrorIf: {
<function (type parameter) E in <E, XE, XR>(predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): <A, R>(self: Effect<A, E, R>) => Effect<A, E | XE, R | XR>E, function (type parameter) XE in <E, XE, XR>(predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): <A, R>(self: Effect<A, E, R>) => Effect<A, E | XE, R | XR>XE, function (type parameter) XR in <E, XE, XR>(predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): <A, R>(self: Effect<A, E, R>) => Effect<A, E | XE, R | XR>XR>(
predicate: Predicate.Predicate<Cause.Cause<E>>predicate: import PredicatePredicate.interface Predicate<in A>A function that decides whether a value of type A satisfies a condition.
When to use
Use when you want a reusable boolean check for A, especially when you plan
to combine checks with
and
/
or
or pass a predicate to arrays
and iterables.
Details
A predicate returns true or false and never throws by itself. It does not
narrow types unless you use Refinement.
Example (Defining a predicate)
import { Predicate } from "effect"
const isPositive: Predicate.Predicate<number> = (n) => n > 0
console.log(isPositive(1))
Type-level utilities for working with
Predicate
types.
When to use
Use when you need to extract input types from predicate signatures while
writing generic helpers over predicate types.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting predicate input)
import { Predicate } from "effect"
type IsString = Predicate.Predicate<string>
type Input = Predicate.Predicate.In<IsString>
Predicate<import CauseCause.type Cause.Cause = /*unresolved*/ anyCause<function (type parameter) E in <E, XE, XR>(predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): <A, R>(self: Effect<A, E, R>) => Effect<A, E | XE, R | XR>E>>,
f: (
cause: Cause.Cause<E>
) => Effect<void, XE, XR>
f: (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, XE, XR>(predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): <A, R>(self: Effect<A, E, R>) => Effect<A, E | XE, R | XR>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<void, function (type parameter) XE in <E, XE, XR>(predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): <A, R>(self: Effect<A, E, R>) => Effect<A, E | XE, R | XR>XE, function (type parameter) XR in <E, XE, XR>(predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): <A, R>(self: Effect<A, E, R>) => Effect<A, E | XE, R | XR>XR>
): <function (type parameter) A in <A, R>(self: Effect<A, E, R>): Effect<A, E | XE, R | XR>A, function (type parameter) R in <A, R>(self: Effect<A, E, R>): Effect<A, E | XE, R | XR>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 <A, R>(self: Effect<A, E, R>): Effect<A, E | XE, R | XR>A, function (type parameter) E in <E, XE, XR>(predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): <A, R>(self: Effect<A, E, R>) => Effect<A, E | XE, R | XR>E, function (type parameter) R in <A, R>(self: Effect<A, E, R>): Effect<A, E | XE, R | XR>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) A in <A, R>(self: Effect<A, E, R>): Effect<A, E | XE, R | XR>A, function (type parameter) E in <E, XE, XR>(predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): <A, R>(self: Effect<A, E, R>) => Effect<A, E | XE, R | XR>E | function (type parameter) XE in <E, XE, XR>(predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): <A, R>(self: Effect<A, E, R>) => Effect<A, E | XE, R | XR>XE, function (type parameter) R in <A, R>(self: Effect<A, E, R>): Effect<A, E | XE, R | XR>R | function (type parameter) XR in <E, XE, XR>(predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): <A, R>(self: Effect<A, E, R>) => Effect<A, E | XE, R | XR>XR>
<function (type parameter) A in <A, E, R, XE, XR>(self: Effect<A, E, R>, predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): Effect<A, E | XE, R | XR>A, function (type parameter) E in <A, E, R, XE, XR>(self: Effect<A, E, R>, predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): Effect<A, E | XE, R | XR>E, function (type parameter) R in <A, E, R, XE, XR>(self: Effect<A, E, R>, predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): Effect<A, E | XE, R | XR>R, function (type parameter) XE in <A, E, R, XE, XR>(self: Effect<A, E, R>, predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): Effect<A, E | XE, R | XR>XE, function (type parameter) XR in <A, E, R, XE, XR>(self: Effect<A, E, R>, predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): Effect<A, E | XE, R | XR>XR>(
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, XE, XR>(self: Effect<A, E, R>, predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): Effect<A, E | XE, R | XR>A, function (type parameter) E in <A, E, R, XE, XR>(self: Effect<A, E, R>, predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): Effect<A, E | XE, R | XR>E, function (type parameter) R in <A, E, R, XE, XR>(self: Effect<A, E, R>, predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): Effect<A, E | XE, R | XR>R>,
predicate: Predicate.Predicate<Cause.Cause<E>>predicate: import PredicatePredicate.interface Predicate<in A>A function that decides whether a value of type A satisfies a condition.
When to use
Use when you want a reusable boolean check for A, especially when you plan
to combine checks with
and
/
or
or pass a predicate to arrays
and iterables.
Details
A predicate returns true or false and never throws by itself. It does not
narrow types unless you use Refinement.
Example (Defining a predicate)
import { Predicate } from "effect"
const isPositive: Predicate.Predicate<number> = (n) => n > 0
console.log(isPositive(1))
Type-level utilities for working with
Predicate
types.
When to use
Use when you need to extract input types from predicate signatures while
writing generic helpers over predicate types.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting predicate input)
import { Predicate } from "effect"
type IsString = Predicate.Predicate<string>
type Input = Predicate.Predicate.In<IsString>
Predicate<import CauseCause.type Cause.Cause = /*unresolved*/ anyCause<function (type parameter) E in <A, E, R, XE, XR>(self: Effect<A, E, R>, predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): Effect<A, E | XE, R | XR>E>>,
f: (
cause: Cause.Cause<E>
) => Effect<void, XE, XR>
f: (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, XE, XR>(self: Effect<A, E, R>, predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): Effect<A, E | XE, R | XR>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<void, function (type parameter) XE in <A, E, R, XE, XR>(self: Effect<A, E, R>, predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): Effect<A, E | XE, R | XR>XE, function (type parameter) XR in <A, E, R, XE, XR>(self: Effect<A, E, R>, predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): Effect<A, E | XE, R | XR>XR>
): 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, XE, XR>(self: Effect<A, E, R>, predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): Effect<A, E | XE, R | XR>A, function (type parameter) E in <A, E, R, XE, XR>(self: Effect<A, E, R>, predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): Effect<A, E | XE, R | XR>E | function (type parameter) XE in <A, E, R, XE, XR>(self: Effect<A, E, R>, predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): Effect<A, E | XE, R | XR>XE, function (type parameter) R in <A, E, R, XE, XR>(self: Effect<A, E, R>, predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): Effect<A, E | XE, R | XR>R | function (type parameter) XR in <A, E, R, XE, XR>(self: Effect<A, E, R>, predicate: Predicate.Predicate<Cause.Cause<E>>, f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>): Effect<A, E | XE, R | XR>XR>
} = import internalinternal.const onErrorIf: {
<E, XE, XR>(
predicate: Predicate.Predicate<
Cause.Cause<E>
>,
f: (
cause: Cause.Cause<E>
) => Effect.Effect<void, XE, XR>
): <A, R>(
self: Effect.Effect<A, E, R>
) => Effect.Effect<A, E | XE, R | XR>
<A, E, R, XE, XR>(
self: Effect.Effect<A, E, R>,
predicate: Predicate.Predicate<
Cause.Cause<E>
>,
f: (
cause: Cause.Cause<E>
) => Effect.Effect<void, XE, XR>
): Effect.Effect<A, E | XE, R | XR>
}
onErrorIf