<K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>
readonly idleTimeToLive?:
| Duration.Input
| ((key: K) => Duration.Input)
| undefined
readonly capacity?: undefined
}): Effect.Effect<RcMap<K, A, E>, never, Scope.Scope | R>
<K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>
readonly idleTimeToLive?:
| Duration.Input
| ((key: K) => Duration.Input)
| undefined
readonly capacity: number
}): Effect.Effect<
RcMap<K, A, E | Cause.ExceededCapacityError>,
never,
Scope.Scope | R
>Creates an RcMap that can contain multiple reference counted resources that can be indexed
by a key. The resources are lazily acquired on the first call to get and
released when the last reference is released.
When to use
Use to create a scoped reference-counted map for resources that should be acquired once per key and shared while in use.
Details
Complex keys can extend Equal and Hash to allow lookups by value.
capacity: The maximum number of resources that can be held in the map.idleTimeToLive: When the reference count reaches zero, the resource will be released after this duration.
Example (Creating a reference-counted map)
import { Effect, RcMap } from "effect"
Effect.gen(function*() {
const map = yield* RcMap.make({
lookup: (key: string) =>
Effect.acquireRelease(
Effect.succeed(`acquired ${key}`),
() => Effect.log(`releasing ${key}`)
)
})
// Get "foo" from the map twice, which will only acquire it once.
// It will then be released once the scope closes.
yield* RcMap.get(map, "foo").pipe(
Effect.andThen(RcMap.get(map, "foo")),
Effect.scoped
)
})export const const make: {
<K, A, E, R>(options: {
readonly lookup: (
key: K
) => Effect.Effect<A, E, R>
readonly idleTimeToLive?:
| Duration.Input
| ((key: K) => Duration.Input)
| undefined
readonly capacity?: undefined
}): Effect.Effect<
RcMap<K, A, E>,
never,
Scope.Scope | R
>
<K, A, E, R>(options: {
readonly lookup: (
key: K
) => Effect.Effect<A, E, R>
readonly idleTimeToLive?:
| Duration.Input
| ((key: K) => Duration.Input)
| undefined
readonly capacity: number
}): Effect.Effect<
RcMap<K, A, E | Cause.ExceededCapacityError>,
never,
Scope.Scope | R
>
}
Creates an RcMap that can contain multiple reference counted resources that can be indexed
by a key. The resources are lazily acquired on the first call to get and
released when the last reference is released.
When to use
Use to create a scoped reference-counted map for resources that should be
acquired once per key and shared while in use.
Details
Complex keys can extend Equal and Hash to allow lookups by value.
capacity: The maximum number of resources that can be held in the map.
idleTimeToLive: When the reference count reaches zero, the resource will be released after this duration.
Example (Creating a reference-counted map)
import { Effect, RcMap } from "effect"
Effect.gen(function*() {
const map = yield* RcMap.make({
lookup: (key: string) =>
Effect.acquireRelease(
Effect.succeed(`acquired ${key}`),
() => Effect.log(`releasing ${key}`)
)
})
// Get "foo" from the map twice, which will only acquire it once.
// It will then be released once the scope closes.
yield* RcMap.get(map, "foo").pipe(
Effect.andThen(RcMap.get(map, "foo")),
Effect.scoped
)
})
make: {
<function (type parameter) K in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: undefined;
}): Effect.Effect<RcMap<K, A, E>, never, Scope.Scope | R>
K, function (type parameter) A in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: undefined;
}): Effect.Effect<RcMap<K, A, E>, never, Scope.Scope | R>
A, function (type parameter) E in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: undefined;
}): Effect.Effect<RcMap<K, A, E>, never, Scope.Scope | R>
E, function (type parameter) R in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: undefined;
}): Effect.Effect<RcMap<K, A, E>, never, Scope.Scope | R>
R>(options: {
readonly lookup: (
key: K
) => Effect.Effect<A, E, R>
readonly idleTimeToLive?:
| Duration.Input
| ((key: K) => Duration.Input)
| undefined
readonly capacity?: undefined
}
options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>lookup: (key: Kkey: function (type parameter) K in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: undefined;
}): Effect.Effect<RcMap<K, A, E>, never, Scope.Scope | R>
K) => import EffectEffect.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 <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: undefined;
}): Effect.Effect<RcMap<K, A, E>, never, Scope.Scope | R>
A, function (type parameter) E in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: undefined;
}): Effect.Effect<RcMap<K, A, E>, never, Scope.Scope | R>
E, function (type parameter) R in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: undefined;
}): Effect.Effect<RcMap<K, A, E>, never, Scope.Scope | R>
R>
readonly idleTimeToLive?: | Duration.Input
| ((key: K) => Duration.Input)
| undefined
idleTimeToLive?: import DurationDuration.type Input =
| number
| bigint
| Duration.Duration
| readonly [seconds: number, nanos: number]
| `${number} nano`
| `${number} nanos`
| `${number} micro`
| `${number} micros`
| `${number} milli`
| `${number} millis`
| `${number} second`
| `${number} seconds`
| `${number} minute`
| `${number} minutes`
| `${number} hour`
| `${number} hours`
| `${number} day`
| `${number} days`
| `${number} week`
| `${number} weeks`
| "Infinity"
| "-Infinity"
| Duration.DurationObject
Valid input types that can be converted to a Duration.
When to use
Use when an API should accept any value that Effect can convert into a
Duration, including existing durations, millisecond numbers, nanosecond
bigints, high-resolution tuples, duration strings, infinity strings, or
duration objects.
Details
String inputs accept values like "10 seconds", "500 millis",
"Infinity", and "-Infinity". Finite fractional values that are
normalized to nanoseconds are rounded to the nearest nanosecond, with ties
away from zero.
Input | ((key: Kkey: function (type parameter) K in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: undefined;
}): Effect.Effect<RcMap<K, A, E>, never, Scope.Scope | R>
K) => import DurationDuration.type Input =
| number
| bigint
| Duration.Duration
| readonly [seconds: number, nanos: number]
| `${number} nano`
| `${number} nanos`
| `${number} micro`
| `${number} micros`
| `${number} milli`
| `${number} millis`
| `${number} second`
| `${number} seconds`
| `${number} minute`
| `${number} minutes`
| `${number} hour`
| `${number} hours`
| `${number} day`
| `${number} days`
| `${number} week`
| `${number} weeks`
| "Infinity"
| "-Infinity"
| Duration.DurationObject
Valid input types that can be converted to a Duration.
When to use
Use when an API should accept any value that Effect can convert into a
Duration, including existing durations, millisecond numbers, nanosecond
bigints, high-resolution tuples, duration strings, infinity strings, or
duration objects.
Details
String inputs accept values like "10 seconds", "500 millis",
"Infinity", and "-Infinity". Finite fractional values that are
normalized to nanoseconds are rounded to the nearest nanosecond, with ties
away from zero.
Input) | undefined
readonly capacity?: undefinedcapacity?: undefined
}): import EffectEffect.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<interface RcMap<in out K, in out A, in out E = never>An RcMap is a reference-counted map data structure that manages the lifecycle
of resources indexed by keys. Resources are lazily acquired and automatically
released when no longer in use.
When to use
Use to share scoped resources by key while automatically releasing them after
their last active reference is gone.
Example (Inspecting a reference-counted map)
import { Effect, RcMap } from "effect"
Effect.gen(function*() {
// Create an RcMap that manages database connections
const dbConnectionMap = yield* RcMap.make({
lookup: (dbName: string) =>
Effect.acquireRelease(
Effect.succeed(`Connection to ${dbName}`),
(conn) => Effect.log(`Closing ${conn}`)
),
capacity: 10,
idleTimeToLive: "5 minutes"
})
// The RcMap interface provides access to:
// - lookup: Function to acquire resources
// - capacity: Maximum number of resources
// - idleTimeToLive: Time before idle resources are released
// - state: Current state of the map
console.log(`Capacity: ${dbConnectionMap.capacity}`)
}).pipe(Effect.scoped)
RcMap<function (type parameter) K in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: undefined;
}): Effect.Effect<RcMap<K, A, E>, never, Scope.Scope | R>
K, function (type parameter) A in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: undefined;
}): Effect.Effect<RcMap<K, A, E>, never, Scope.Scope | R>
A, function (type parameter) E in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: undefined;
}): Effect.Effect<RcMap<K, A, E>, never, Scope.Scope | R>
E>, never, import ScopeScope.Scope | function (type parameter) R in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: undefined;
}): Effect.Effect<RcMap<K, A, E>, never, Scope.Scope | R>
R>
<function (type parameter) K in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity: number;
}): Effect.Effect<RcMap<K, A, E | Cause.ExceededCapacityError>, never, Scope.Scope | R>
K, function (type parameter) A in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity: number;
}): Effect.Effect<RcMap<K, A, E | Cause.ExceededCapacityError>, never, Scope.Scope | R>
A, function (type parameter) E in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity: number;
}): Effect.Effect<RcMap<K, A, E | Cause.ExceededCapacityError>, never, Scope.Scope | R>
E, function (type parameter) R in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity: number;
}): Effect.Effect<RcMap<K, A, E | Cause.ExceededCapacityError>, never, Scope.Scope | R>
R>(options: {
readonly lookup: (
key: K
) => Effect.Effect<A, E, R>
readonly idleTimeToLive?:
| Duration.Input
| ((key: K) => Duration.Input)
| undefined
readonly capacity: number
}
options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>lookup: (key: Kkey: function (type parameter) K in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity: number;
}): Effect.Effect<RcMap<K, A, E | Cause.ExceededCapacityError>, never, Scope.Scope | R>
K) => import EffectEffect.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 <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity: number;
}): Effect.Effect<RcMap<K, A, E | Cause.ExceededCapacityError>, never, Scope.Scope | R>
A, function (type parameter) E in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity: number;
}): Effect.Effect<RcMap<K, A, E | Cause.ExceededCapacityError>, never, Scope.Scope | R>
E, function (type parameter) R in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity: number;
}): Effect.Effect<RcMap<K, A, E | Cause.ExceededCapacityError>, never, Scope.Scope | R>
R>
readonly idleTimeToLive?: | Duration.Input
| ((key: K) => Duration.Input)
| undefined
idleTimeToLive?: import DurationDuration.type Input =
| number
| bigint
| Duration.Duration
| readonly [seconds: number, nanos: number]
| `${number} nano`
| `${number} nanos`
| `${number} micro`
| `${number} micros`
| `${number} milli`
| `${number} millis`
| `${number} second`
| `${number} seconds`
| `${number} minute`
| `${number} minutes`
| `${number} hour`
| `${number} hours`
| `${number} day`
| `${number} days`
| `${number} week`
| `${number} weeks`
| "Infinity"
| "-Infinity"
| Duration.DurationObject
Valid input types that can be converted to a Duration.
When to use
Use when an API should accept any value that Effect can convert into a
Duration, including existing durations, millisecond numbers, nanosecond
bigints, high-resolution tuples, duration strings, infinity strings, or
duration objects.
Details
String inputs accept values like "10 seconds", "500 millis",
"Infinity", and "-Infinity". Finite fractional values that are
normalized to nanoseconds are rounded to the nearest nanosecond, with ties
away from zero.
Input | ((key: Kkey: function (type parameter) K in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity: number;
}): Effect.Effect<RcMap<K, A, E | Cause.ExceededCapacityError>, never, Scope.Scope | R>
K) => import DurationDuration.type Input =
| number
| bigint
| Duration.Duration
| readonly [seconds: number, nanos: number]
| `${number} nano`
| `${number} nanos`
| `${number} micro`
| `${number} micros`
| `${number} milli`
| `${number} millis`
| `${number} second`
| `${number} seconds`
| `${number} minute`
| `${number} minutes`
| `${number} hour`
| `${number} hours`
| `${number} day`
| `${number} days`
| `${number} week`
| `${number} weeks`
| "Infinity"
| "-Infinity"
| Duration.DurationObject
Valid input types that can be converted to a Duration.
When to use
Use when an API should accept any value that Effect can convert into a
Duration, including existing durations, millisecond numbers, nanosecond
bigints, high-resolution tuples, duration strings, infinity strings, or
duration objects.
Details
String inputs accept values like "10 seconds", "500 millis",
"Infinity", and "-Infinity". Finite fractional values that are
normalized to nanoseconds are rounded to the nearest nanosecond, with ties
away from zero.
Input) | undefined
readonly capacity: numbercapacity: number
}): import EffectEffect.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<interface RcMap<in out K, in out A, in out E = never>An RcMap is a reference-counted map data structure that manages the lifecycle
of resources indexed by keys. Resources are lazily acquired and automatically
released when no longer in use.
When to use
Use to share scoped resources by key while automatically releasing them after
their last active reference is gone.
Example (Inspecting a reference-counted map)
import { Effect, RcMap } from "effect"
Effect.gen(function*() {
// Create an RcMap that manages database connections
const dbConnectionMap = yield* RcMap.make({
lookup: (dbName: string) =>
Effect.acquireRelease(
Effect.succeed(`Connection to ${dbName}`),
(conn) => Effect.log(`Closing ${conn}`)
),
capacity: 10,
idleTimeToLive: "5 minutes"
})
// The RcMap interface provides access to:
// - lookup: Function to acquire resources
// - capacity: Maximum number of resources
// - idleTimeToLive: Time before idle resources are released
// - state: Current state of the map
console.log(`Capacity: ${dbConnectionMap.capacity}`)
}).pipe(Effect.scoped)
RcMap<function (type parameter) K in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity: number;
}): Effect.Effect<RcMap<K, A, E | Cause.ExceededCapacityError>, never, Scope.Scope | R>
K, function (type parameter) A in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity: number;
}): Effect.Effect<RcMap<K, A, E | Cause.ExceededCapacityError>, never, Scope.Scope | R>
A, function (type parameter) E in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity: number;
}): Effect.Effect<RcMap<K, A, E | Cause.ExceededCapacityError>, never, Scope.Scope | R>
E | import CauseCause.ExceededCapacityError>, never, import ScopeScope.Scope | function (type parameter) R in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity: number;
}): Effect.Effect<RcMap<K, A, E | Cause.ExceededCapacityError>, never, Scope.Scope | R>
R>
} = <function (type parameter) K in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: number | undefined;
}): Effect.Effect<...>
K, function (type parameter) A in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: number | undefined;
}): Effect.Effect<...>
A, function (type parameter) E in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: number | undefined;
}): Effect.Effect<...>
E, function (type parameter) R in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: number | undefined;
}): Effect.Effect<...>
R>(options: {
readonly lookup: (
key: K
) => Effect.Effect<A, E, R>
readonly idleTimeToLive?:
| Duration.Input
| ((key: K) => Duration.Input)
| undefined
readonly capacity?: number | undefined
}
options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>lookup: (key: Kkey: function (type parameter) K in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: number | undefined;
}): Effect.Effect<...>
K) => import EffectEffect.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 <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: number | undefined;
}): Effect.Effect<...>
A, function (type parameter) E in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: number | undefined;
}): Effect.Effect<...>
E, function (type parameter) R in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: number | undefined;
}): Effect.Effect<...>
R>
readonly idleTimeToLive?: | Duration.Input
| ((key: K) => Duration.Input)
| undefined
idleTimeToLive?: import DurationDuration.type Input =
| number
| bigint
| Duration.Duration
| readonly [seconds: number, nanos: number]
| `${number} nano`
| `${number} nanos`
| `${number} micro`
| `${number} micros`
| `${number} milli`
| `${number} millis`
| `${number} second`
| `${number} seconds`
| `${number} minute`
| `${number} minutes`
| `${number} hour`
| `${number} hours`
| `${number} day`
| `${number} days`
| `${number} week`
| `${number} weeks`
| "Infinity"
| "-Infinity"
| Duration.DurationObject
Valid input types that can be converted to a Duration.
When to use
Use when an API should accept any value that Effect can convert into a
Duration, including existing durations, millisecond numbers, nanosecond
bigints, high-resolution tuples, duration strings, infinity strings, or
duration objects.
Details
String inputs accept values like "10 seconds", "500 millis",
"Infinity", and "-Infinity". Finite fractional values that are
normalized to nanoseconds are rounded to the nearest nanosecond, with ties
away from zero.
Input | ((key: Kkey: function (type parameter) K in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: number | undefined;
}): Effect.Effect<...>
K) => import DurationDuration.type Input =
| number
| bigint
| Duration.Duration
| readonly [seconds: number, nanos: number]
| `${number} nano`
| `${number} nanos`
| `${number} micro`
| `${number} micros`
| `${number} milli`
| `${number} millis`
| `${number} second`
| `${number} seconds`
| `${number} minute`
| `${number} minutes`
| `${number} hour`
| `${number} hours`
| `${number} day`
| `${number} days`
| `${number} week`
| `${number} weeks`
| "Infinity"
| "-Infinity"
| Duration.DurationObject
Valid input types that can be converted to a Duration.
When to use
Use when an API should accept any value that Effect can convert into a
Duration, including existing durations, millisecond numbers, nanosecond
bigints, high-resolution tuples, duration strings, infinity strings, or
duration objects.
Details
String inputs accept values like "10 seconds", "500 millis",
"Infinity", and "-Infinity". Finite fractional values that are
normalized to nanoseconds are rounded to the nearest nanosecond, with ties
away from zero.
Input) | undefined
readonly capacity?: number | undefinedcapacity?: number | undefined
}) =>
import EffectEffect.const withFiber: <
A,
E = never,
R = never
>(
evaluate: (
fiber: Fiber<unknown, unknown>
) => Effect<A, E, R>
) => Effect<A, E, R>
Provides access to the current fiber within an effect computation.
Example (Reading the current fiber)
import { Effect } from "effect"
const program = Effect.withFiber((fiber) =>
Effect.succeed(`Fiber ID: ${fiber.id}`)
)
Effect.runPromise(program).then(console.log)
// Output: Fiber ID: 1
withFiber<interface RcMap<in out K, in out A, in out E = never>An RcMap is a reference-counted map data structure that manages the lifecycle
of resources indexed by keys. Resources are lazily acquired and automatically
released when no longer in use.
When to use
Use to share scoped resources by key while automatically releasing them after
their last active reference is gone.
Example (Inspecting a reference-counted map)
import { Effect, RcMap } from "effect"
Effect.gen(function*() {
// Create an RcMap that manages database connections
const dbConnectionMap = yield* RcMap.make({
lookup: (dbName: string) =>
Effect.acquireRelease(
Effect.succeed(`Connection to ${dbName}`),
(conn) => Effect.log(`Closing ${conn}`)
),
capacity: 10,
idleTimeToLive: "5 minutes"
})
// The RcMap interface provides access to:
// - lookup: Function to acquire resources
// - capacity: Maximum number of resources
// - idleTimeToLive: Time before idle resources are released
// - state: Current state of the map
console.log(`Capacity: ${dbConnectionMap.capacity}`)
}).pipe(Effect.scoped)
RcMap<function (type parameter) K in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: number | undefined;
}): Effect.Effect<...>
K, function (type parameter) A in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: number | undefined;
}): Effect.Effect<...>
A, function (type parameter) E in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: number | undefined;
}): Effect.Effect<...>
E>, never, function (type parameter) R in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: number | undefined;
}): Effect.Effect<...>
R | import ScopeScope.Scope>((fiber: Fiber.Fiber<unknown, unknown>(parameter) fiber: {
id: number;
currentOpCount: number;
getRef: <A>(ref: Context.Reference<A>) => A;
context: Context.Context<never>;
setContext: (context: Context.Context<never>) => void;
currentScheduler: Scheduler;
currentDispatcher: SchedulerDispatcher;
currentSpan: AnySpan | undefined;
currentLogLevel: LogLevel;
minimumLogLevel: LogLevel;
currentStackFrame: StackFrame | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
addObserver: (cb: (exit: Exit<A, E>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<A, E> | undefined;
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; <…;
}
fiber) => {
const const context: Context.Context<
Scope.Scope | R
>
const context: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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;
}
context = fiber: Fiber.Fiber<unknown, unknown>(parameter) fiber: {
id: number;
currentOpCount: number;
getRef: <A>(ref: Context.Reference<A>) => A;
context: Context.Context<never>;
setContext: (context: Context.Context<never>) => void;
currentScheduler: Scheduler;
currentDispatcher: SchedulerDispatcher;
currentSpan: AnySpan | undefined;
currentLogLevel: LogLevel;
minimumLogLevel: LogLevel;
currentStackFrame: StackFrame | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
addObserver: (cb: (exit: Exit<A, E>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<A, E> | undefined;
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; <…;
}
fiber.Fiber<out A, out E = never>.context: Context.Context<never>(property) Fiber<out A, out E = never>.context: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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;
}
context as import ContextContext.interface Context<in Services>Immutable collection of service implementations used for dependency
injection in Effect programs.
Details
The type parameter tracks the service identifiers available in the context.
At runtime, services are stored by each key's string key.
Example (Creating a context with multiple services)
import { Context } from "effect"
// Create a context with multiple services
const Logger = Context.Service<{ log: (msg: string) => void }>("Logger")
const Database = Context.Service<{ query: (sql: string) => string }>(
"Database"
)
const context = Context.make(Logger, {
log: (msg: string) => console.log(msg)
})
.pipe(Context.add(Database, { query: (sql) => `Result: ${sql}` }))
Context<function (type parameter) R in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: number | undefined;
}): Effect.Effect<...>
R | import ScopeScope.Scope>
const const scope: Scope.Scopeconst scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope = import ContextContext.const get: {
<Services, I extends Services, S>(
service: Key<I, S>
): (self: Context<Services>) => S
<Services, I extends Services, S>(
self: Context<Services>,
service: Key<I, S>
): S
}
get(const context: Context.Context<
Scope.Scope | R
>
const context: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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;
}
context, import ScopeScope.const Scope: Context.Service<Scope, Scope>const Scope: {
key: string;
Service: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
};
of: (this: void, self: Scope.Scope) => Scope.Scope;
context: (self: Scope.Scope) => Context.Context<Scope.Scope>;
use: (f: (service: Scope.Scope) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, Scope.Scope | R>;
useSync: (f: (service: Scope.Scope) => A) => Effect.Effect<A, never, Scope.Scope>;
Identifier: Identifier;
stack: string | undefined;
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;
}
A Scope represents a context where resources can be acquired and
automatically cleaned up when the scope is closed. Scopes can use
either sequential or parallel finalization strategies.
Example (Managing scoped resources)
import { Effect, Exit, Scope } from "effect"
const program = Effect.gen(function*() {
const scope = yield* Scope.make("sequential")
// Scope has a strategy and state
console.log(scope.strategy) // "sequential"
console.log(scope.state._tag) // "Open"
// Close the scope
yield* Scope.close(scope, Exit.void)
console.log(scope.state._tag) // "Closed"
})
Service tag for the active resource lifetime.
When to use
Use to access the active lifetime when registering finalizers or sharing
resources with the surrounding scope.
Example (Accessing the scope service)
import { Effect, Scope } from "effect"
const program = Effect.gen(function*() {
// Access the scope from the context
const scope = yield* Scope.Scope
// Use the scope for resource management
yield* Scope.addFinalizer(scope, Effect.log("Cleanup"))
})
// Provide a scope to the program
const scoped = Effect.scoped(program)
Scope)
const const self: RcMap<K, A, E>const self: {
lookup: (key: K) => Effect.Effect<A, E, Scope.Scope>;
context: Context.Context<never>;
scope: Scope.Scope;
idleTimeToLive: (key: K) => Duration.Duration;
capacity: number;
state: State<K, A, 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; <…;
}
self = const makeUnsafe: <K, A, E>(options: {
readonly lookup: (
key: K
) => Effect.Effect<A, E, Scope.Scope>
readonly context: Context.Context<never>
readonly scope: Scope.Scope
readonly idleTimeToLive: (
key: K
) => Duration.Duration
readonly capacity: number
}) => RcMap<K, A, E>
makeUnsafe<function (type parameter) K in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: number | undefined;
}): Effect.Effect<...>
K, function (type parameter) A in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: number | undefined;
}): Effect.Effect<...>
A, function (type parameter) E in <K, A, E, R>(options: {
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
readonly idleTimeToLive?: Duration.Input | ((key: K) => Duration.Input) | undefined;
readonly capacity?: number | undefined;
}): Effect.Effect<...>
E>({
lookup: (
key: K
) => Effect.Effect<A, E, Scope.Scope>
lookup: options: {
readonly lookup: (
key: K
) => Effect.Effect<A, E, R>
readonly idleTimeToLive?:
| Duration.Input
| ((key: K) => Duration.Input)
| undefined
readonly capacity?: number | undefined
}
options.lookup: (key: K) => Effect.Effect<A, E, R>lookup as any,
context: Context.Context<Scope.Scope | R>(property) context: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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;
}
context,
scope: Scope.Scope(property) scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope,
idleTimeToLive: (key: K) => Duration.DurationidleTimeToLive: typeof options: {
readonly lookup: (
key: K
) => Effect.Effect<A, E, R>
readonly idleTimeToLive?:
| Duration.Input
| ((key: K) => Duration.Input)
| undefined
readonly capacity?: number | undefined
}
options.idleTimeToLive?: | Duration.Input
| ((key: K) => Duration.Input)
| undefined
idleTimeToLive === "function"
? flow<[key: K], Duration.Input, Duration.Duration>(ab: (key: K) => Duration.Input, bc: (b: Duration.Input) => Duration.Duration): (key: K) => Duration.Duration (+8 overloads)Performs left-to-right function composition.
When to use
Use to build a reusable function from a left-to-right sequence of
transformations.
Details
The first function may have any arity. Every following function must be
unary.
Example (Composing functions left to right)
import { flow } from "effect"
import * as assert from "node:assert"
const len = (s: string): number => s.length
const double = (n: number): number => n * 2
const f = flow(len, double)
assert.strictEqual(f("aaa"), 6)
flow(options: {
readonly lookup: (
key: K
) => Effect.Effect<A, E, R>
readonly idleTimeToLive?:
| Duration.Input
| ((key: K) => Duration.Input)
| undefined
readonly capacity?: number | undefined
}
options.idleTimeToLive?: | Duration.Input
| ((key: K) => Duration.Input)
| undefined
idleTimeToLive, import DurationDuration.const fromInputUnsafe: (
input: Input
) => Duration
Decodes a Duration.Input into a Duration.
When to use
Use when the input has already been validated or comes from a trusted source
and throwing is acceptable for invalid duration syntax.
Gotchas
If the input is not a valid Duration.Input, it throws an error.
Example (Decoding duration inputs)
import { Duration } from "effect"
const duration1 = Duration.fromInputUnsafe(1000) // 1000 milliseconds
const duration2 = Duration.fromInputUnsafe("5 seconds")
const duration3 = Duration.fromInputUnsafe("Infinity")
const duration4 = Duration.fromInputUnsafe([2, 500_000_000]) // 2 seconds and 500ms
fromInputUnsafe)
: constant<A>(value: A): LazyArg<A>Creates a zero-argument function that always returns the provided value.
When to use
Use when you need a thunk or callback that returns the same value on every
invocation.
Example (Creating a constant thunk)
import { Function } from "effect"
import * as assert from "node:assert"
const constNull = Function.constant(null)
assert.deepStrictEqual(constNull(), null)
assert.deepStrictEqual(constNull(), null)
constant(import DurationDuration.const fromInputUnsafe: (
input: Input
) => Duration
Decodes a Duration.Input into a Duration.
When to use
Use when the input has already been validated or comes from a trusted source
and throwing is acceptable for invalid duration syntax.
Gotchas
If the input is not a valid Duration.Input, it throws an error.
Example (Decoding duration inputs)
import { Duration } from "effect"
const duration1 = Duration.fromInputUnsafe(1000) // 1000 milliseconds
const duration2 = Duration.fromInputUnsafe("5 seconds")
const duration3 = Duration.fromInputUnsafe("Infinity")
const duration4 = Duration.fromInputUnsafe([2, 500_000_000]) // 2 seconds and 500ms
fromInputUnsafe(options: {
readonly lookup: (
key: K
) => Effect.Effect<A, E, R>
readonly idleTimeToLive?:
| Duration.Input
| ((key: K) => Duration.Input)
| undefined
readonly capacity?: number | undefined
}
options.idleTimeToLive?: | Duration.Input
| ((key: K) => Duration.Input)
| undefined
idleTimeToLive ?? import DurationDuration.const zero: Durationconst zero: {
value: DurationValue;
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;
}
A Duration representing zero time.
Example (Referencing the zero duration)
import { Duration } from "effect"
console.log(Duration.toMillis(Duration.zero)) // 0
zero)),
capacity: numbercapacity: var Math: MathAn intrinsic object that provides basic mathematics functionality and constants.
Math.Math.max(...values: number[]): numberReturns the larger of a set of supplied numeric expressions.
max(options: {
readonly lookup: (
key: K
) => Effect.Effect<A, E, R>
readonly idleTimeToLive?:
| Duration.Input
| ((key: K) => Duration.Input)
| undefined
readonly capacity?: number | undefined
}
options.capacity?: number | undefinedcapacity ?? var Number: NumberConstructorAn object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.
Number.NumberConstructor.POSITIVE_INFINITY: numberA value greater than the largest number that can be represented in JavaScript.
JavaScript displays POSITIVE_INFINITY values as infinity.
POSITIVE_INFINITY, 0)
})
return import EffectEffect.const as: {
<B>(value: B): <A, E, R>(
self: Effect<A, E, R>
) => Effect<B, E, R>
<A, E, R, B>(
self: Effect<A, E, R>,
value: B
): Effect<B, E, R>
}
as(
import ScopeScope.const addFinalizerExit: (
scope: Scope,
finalizer: (
exit: Exit<any, any>
) => Effect<unknown>
) => Effect<void>
Registers an exit-aware finalizer on a scope.
When to use
Use when cleanup needs to know whether the scope closed with success,
failure, or interruption.
Details
If the scope is open, the finalizer runs when the scope closes and receives
the scope's exit value. If the scope is already closed, the finalizer runs
immediately with the stored exit value.
Example (Adding an exit-aware finalizer)
import { Console, Effect, Exit, Scope } from "effect"
const withResource = Effect.gen(function*() {
const scope = yield* Scope.make()
// Add a finalizer for cleanup
yield* Scope.addFinalizerExit(
scope,
(exit) =>
Console.log(
`Cleaning up resource. Exit: ${
Exit.isSuccess(exit) ? "Success" : "Failure"
}`
)
)
// Use the resource
yield* Console.log("Using resource")
// Close the scope
yield* Scope.close(scope, Exit.void)
})
addFinalizerExit(const scope: Scope.Scopeconst scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope, () => {
if (const self: RcMap<K, A, E>const self: {
lookup: (key: K) => Effect.Effect<A, E, Scope.Scope>;
context: Context.Context<never>;
scope: Scope.Scope;
idleTimeToLive: (key: K) => Duration.Duration;
capacity: number;
state: State<K, A, 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; <…;
}
self.RcMap<K, A, E>.state: State<K, A, E>state._tag: "Open" | "Closed"_tag === "Closed") {
return import EffectEffect.const void: Effect.Effect<void, never, never>(alias) const void: {
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;
}
Returns an effect that succeeds with void.
void
}
const const map: MutableHashMap.MutableHashMap<
K,
State.Entry<A, E>
>
const map: {
backing: Map<K, V>;
buckets: Map<number, NonEmptyArray<K>>;
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;
}
map = const self: RcMap<K, A, E>const self: {
lookup: (key: K) => Effect.Effect<A, E, Scope.Scope>;
context: Context.Context<never>;
scope: Scope.Scope;
idleTimeToLive: (key: K) => Duration.Duration;
capacity: number;
state: State<K, A, 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; <…;
}
self.RcMap<K, A, E>.state: State<K, A, E>(property) RcMap<K, A, E>.state: {
_tag: "Open";
map: MutableHashMap.MutableHashMap<K, Entry<A, E>>;
}
state.State<K, A, E>.Open<K, A, E>.map: MutableHashMap.MutableHashMap<K, Entry<A, E>>(property) State<K, A, E>.Open<K, A, E>.map: {
backing: Map<K, V>;
buckets: Map<number, NonEmptyArray<K>>;
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;
}
map
const self: RcMap<K, A, E>const self: {
lookup: (key: K) => Effect.Effect<A, E, Scope.Scope>;
context: Context.Context<never>;
scope: Scope.Scope;
idleTimeToLive: (key: K) => Duration.Duration;
capacity: number;
state: State<K, A, 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; <…;
}
self.RcMap<K, A, E>.state: State<K, A, E>state = { State<K, A, E>.Closed._tag: "Closed"_tag: "Closed" }
return import EffectEffect.const forEach: {
<
B,
E,
R,
S extends Iterable<any>,
Discard extends boolean = false
>(
f: (
a: Arr.ReadonlyArray.Infer<S>,
i: number
) => Effect<B, E, R>,
options?:
| {
readonly concurrency?:
| Concurrency
| undefined
readonly discard?: Discard | undefined
}
| undefined
): (
self: S
) => Effect<
Discard extends false
? Arr.ReadonlyArray.With<S, B>
: void,
E,
R
>
<
B,
E,
R,
S extends Iterable<any>,
Discard extends boolean = false
>(
self: S,
f: (
a: Arr.ReadonlyArray.Infer<S>,
i: number
) => Effect<B, E, R>,
options?:
| {
readonly concurrency?:
| Concurrency
| undefined
readonly discard?: Discard | undefined
}
| undefined
): Effect<
Discard extends false
? Arr.ReadonlyArray.With<S, B>
: void,
E,
R
>
}
forEach(
const map: MutableHashMap.MutableHashMap<
K,
State.Entry<A, E>
>
const map: {
backing: Map<K, V>;
buckets: Map<number, NonEmptyArray<K>>;
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;
}
map,
([, entry: State.Entry<A, E>(parameter) entry: {
deferred: Deferred.Deferred<A, E>;
scope: Scope.Closeable;
finalizer: Effect.Effect<void>;
idleTimeToLive: Duration.Duration;
fiber: Fiber.Fiber<void> | undefined;
expiresAt: number;
refCount: number;
}
entry]) => import EffectEffect.const exit: <A, E, R>(
self: Effect<A, E, R>
) => Effect<Exit.Exit<A, E>, never, R>
Transforms an effect to encapsulate both failure and success using the Exit
data type.
When to use
Use when you need to inspect the full outcome, including typed failures, defects,
and interruptions.
Details
exit wraps an effect's success or failure inside an Exit type, allowing
you to handle both cases explicitly.
The resulting effect cannot fail because the failure is encapsulated within
the Exit.Failure type. The error type is set to never, indicating that
the effect is structured to never fail directly.
Example (Capturing completion as Exit)
import { Effect } from "effect"
const success = Effect.succeed(42)
const failure = Effect.fail("Something went wrong")
const program1 = Effect.exit(success)
const program2 = Effect.exit(failure)
Effect.runPromise(program1).then(console.log)
// { _id: 'Exit', _tag: 'Success', value: 42 }
Effect.runPromise(program2).then(console.log)
// { _id: 'Exit', _tag: 'Failure', cause: { _id: 'Cause', _tag: 'Fail', failure: 'Something went wrong' } }
exit(import ScopeScope.const close: <A, E>(
self: Scope,
exit: Exit<A, E>
) => Effect<void>
Closes a scope and runs its registered finalizers.
When to use
Use to close a scope manually with a specific exit value.
Details
Finalizers run in the scope's configured order and receive the supplied
Exit.
Example (Running scope finalizers)
import { Console, Effect, Exit, Scope } from "effect"
const resourceManagement = Effect.gen(function*() {
const scope = yield* Scope.make("sequential")
// Add multiple finalizers
yield* Scope.addFinalizer(scope, Console.log("Close database connection"))
yield* Scope.addFinalizer(scope, Console.log("Close file handle"))
yield* Scope.addFinalizer(scope, Console.log("Release memory"))
// Do some work...
yield* Console.log("Performing operations...")
// Close scope - finalizers run in reverse order of registration
yield* Scope.close(scope, Exit.succeed("Success!"))
// Output: "Release memory", "Close file handle", "Close database connection"
})
close(entry: State.Entry<A, E>(parameter) entry: {
deferred: Deferred.Deferred<A, E>;
scope: Scope.Closeable;
finalizer: Effect.Effect<void>;
idleTimeToLive: Duration.Duration;
fiber: Fiber.Fiber<void> | undefined;
expiresAt: number;
refCount: number;
}
entry.State<K, A, E>.Entry<A, E>.scope: Scope.Closeable(property) State<K, A, E>.Entry<A, E>.scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope, import ExitExit.const void: Exit.Exit<void, never>Provides a pre-allocated successful Exit with a void value.
When to use
Use when you need a shared successful Exit with no meaningful value.
Details
Equivalent to Exit.succeed(undefined) but shared as a single instance,
avoiding allocation for a common case.
Example (Referencing the void Exit)
import { Exit } from "effect"
const exit = Exit.void
console.log(Exit.isSuccess(exit)) // true
void))
).Pipeable.pipe<Effect.Effect<Exit.Exit<void, never>[], never, never>, Effect.Effect<Exit.Exit<void, never>[], never, never>>(this: Effect.Effect<Exit.Exit<void, never>[], never, never>, ab: (_: Effect.Effect<Exit.Exit<void, never>[], never, never>) => Effect.Effect<Exit.Exit<void, never>[], never, never>): Effect.Effect<Exit.Exit<void, never>[], never, never> (+21 overloads)pipe(
import EffectEffect.const tap: {
<A, B, E2, R2>(
f: (a: NoInfer<A>) => Effect<B, E2, R2>
): <E, R>(
self: Effect<A, E, R>
) => Effect<A, E | E2, R | R2>
<B, E2, R2>(f: Effect<B, E2, R2>): <A, E, R>(
self: Effect<A, E, R>
) => Effect<A, E | E2, R | R2>
<A, E, R, B, E2, R2>(
self: Effect<A, E, R>,
f: (a: NoInfer<A>) => Effect<B, E2, R2>
): Effect<A, E | E2, R | R2>
<A, E, R, B, E2, R2>(
self: Effect<A, E, R>,
f: Effect<B, E2, R2>
): Effect<A, E | E2, R | R2>
}
tap(() =>
import EffectEffect.const sync: <A>(
thunk: LazyArg<A>
) => Effect<A>
Creates an Effect that represents a synchronous side-effectful computation.
When to use
Use when you need to wrap a synchronous side-effectful operation that is not
expected to throw.
Details
The provided function is evaluated lazily when the effect runs.
Gotchas
The function must not throw. If it throws, the thrown value is treated as a
defect, not as a typed failure. Use try when throwing is expected.
Example (Capturing synchronous logging in an Effect)
import { Effect } from "effect"
const log = (message: string) =>
Effect.sync(() => {
console.log(message) // side effect
})
// ┌─── Effect<void, never, never>
// ▼
const program = log("Hello, World!")
sync(() => {
import MutableHashMapMutableHashMap.const clear: <K, V>(
self: MutableHashMap<K, V>
) => MutableHashMap<K, V>
Removes all key-value pairs from the MutableHashMap, mutating the map in place.
The map becomes empty after this operation.
When to use
Use to empty a mutable hash map while keeping the same map instance.
Example (Clearing all entries)
import { MutableHashMap } from "effect"
const map = MutableHashMap.make(
["key1", 42],
["key2", 100],
["key3", 200]
)
console.log(MutableHashMap.size(map)) // 3
// Clear all entries
MutableHashMap.clear(map)
console.log(MutableHashMap.size(map)) // 0
console.log(MutableHashMap.has(map, "key1")) // false
// Can still add new entries after clearing
MutableHashMap.set(map, "new", 999)
console.log(MutableHashMap.size(map)) // 1
clear(const map: MutableHashMap.MutableHashMap<
K,
State.Entry<A, E>
>
const map: {
backing: Map<K, V>;
buckets: Map<number, NonEmptyArray<K>>;
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;
}
map)
})
)
)
}),
const self: RcMap<K, A, E>const self: {
lookup: (key: K) => Effect.Effect<A, E, Scope.Scope>;
context: Context.Context<never>;
scope: Scope.Scope;
idleTimeToLive: (key: K) => Duration.Duration;
capacity: number;
state: State<K, A, 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; <…;
}
self
)
})