<A>(): <A2 extends A, E, R>(effect: Effect<A2, E, R>) => Effect<A2, E, R>Ensures that an effect's success type extends a given type A.
Details
This helper is checked at compile time and does not change the effect's runtime behavior.
Example (Constraining the success type)
import { Effect } from "effect"
// Define a constraint that the success type must be a number
const satisfiesNumber = Effect.satisfiesSuccessType<number>()
// This works - Effect<42, never, never> extends Effect<number, never, never>
const validEffect = satisfiesNumber(Effect.succeed(42))
// This would cause a TypeScript compilation error:
// const invalidEffect = satisfiesNumber(Effect.succeed("string"))
// ^^^^^^^^^^^^^^^^^^^^^^
// Type 'string' is not assignable to type 'number'export const const satisfiesSuccessType: <A>() => <
A2 extends A,
E,
R
>(
effect: Effect<A2, E, R>
) => Effect<A2, E, R>
Ensures that an effect's success type extends a given type A.
Details
This helper is checked at compile time and does not change the effect's
runtime behavior.
Example (Constraining the success type)
import { Effect } from "effect"
// Define a constraint that the success type must be a number
const satisfiesNumber = Effect.satisfiesSuccessType<number>()
// This works - Effect<42, never, never> extends Effect<number, never, never>
const validEffect = satisfiesNumber(Effect.succeed(42))
// This would cause a TypeScript compilation error:
// const invalidEffect = satisfiesNumber(Effect.succeed("string"))
// ^^^^^^^^^^^^^^^^^^^^^^
// Type 'string' is not assignable to type 'number'
satisfiesSuccessType = <function (type parameter) A in <A>(): <A2 extends A, E, R>(effect: Effect<A2, E, R>) => Effect<A2, E, R>A>() => <function (type parameter) A2 in <A2 extends A, E, R>(effect: Effect<A2, E, R>): Effect<A2, E, R>A2 extends function (type parameter) A in <A>(): <A2 extends A, E, R>(effect: Effect<A2, E, R>) => Effect<A2, E, R>A, function (type parameter) E in <A2 extends A, E, R>(effect: Effect<A2, E, R>): Effect<A2, E, R>E, function (type parameter) R in <A2 extends A, E, R>(effect: Effect<A2, E, R>): Effect<A2, E, R>R>(effect: Effect<A2, E, R>(parameter) effect: {
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;
}
effect: 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 <A2 extends A, E, R>(effect: Effect<A2, E, R>): Effect<A2, E, R>A2, function (type parameter) E in <A2 extends A, E, R>(effect: Effect<A2, E, R>): Effect<A2, E, R>E, function (type parameter) R in <A2 extends A, E, R>(effect: Effect<A2, E, R>): Effect<A2, E, 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 <A2 extends A, E, R>(effect: Effect<A2, E, R>): Effect<A2, E, R>A2, function (type parameter) E in <A2 extends A, E, R>(effect: Effect<A2, E, R>): Effect<A2, E, R>E, function (type parameter) R in <A2 extends A, E, R>(effect: Effect<A2, E, R>): Effect<A2, E, R>R> => effect: Effect<A2, E, R>(parameter) effect: {
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;
}
effect