Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

RcMap

10 exports Since v3.5.0 Source

Combinators

Since v3.5.0

Signature

declare const get: {
<K>(key: K): <A, E>(self: RcMap<K, A, E>) => Effect<A, E, Scope>;
<K, A, E>(self: RcMap<K, A, E>, key: K): Effect<A, E, Scope>;
}
Since v3.17.7

Signature

declare const has: {
<K>(key: K): <A, E>(self: RcMap<K, A, E>) => Effect<boolean>;
<K, A, E>(self: RcMap<K, A, E>, key: K): Effect<boolean>;
}

Signature

declare const invalidate: {
<K>(key: K): <A, E>(self: RcMap<K, A, E>) => Effect<void>;
<K, A, E>(self: RcMap<K, A, E>, key: K): Effect<void>;
}
Since v3.8.0

Signature

declare const keys: <K, A, E>(self: RcMap<K, A, E>) => Effect.Effect<Array<K>>
Since v3.13.0

Signature

declare const touch: {
<K>(key: K): <A, E>(self: RcMap<K, A, E>) => Effect<void>;
<K, A, E>(self: RcMap<K, A, E>, key: K): Effect<void>;
}

Models

Since v3.5.0

An RcMap 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.

Complex keys can extend Equal and Hash to allow lookups by value.

Options

  • 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. Can be a static duration or a function that returns a duration based on the key.

Signature

declare const make: {
<K, A, E, R>(options: {
readonly capacity?: undefined;
readonly idleTimeToLive?: Duration.DurationInput | (key: K) => Duration.DurationInput;
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
}): Effect<RcMap<K, A, E>, never, Scope | R>;
<K, A, E, R>(options: {
readonly capacity: number;
readonly idleTimeToLive?: Duration.DurationInput | (key: K) => Duration.DurationInput;
readonly lookup: (key: K) => Effect.Effect<A, E, R>;
}): Effect<RcMap<K, A, ExceededCapacityException | E>, never, Scope | R>;
}

Example

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
)
})
Since v3.5.0

RcMap

interface
Since v3.5.0

Signature

interface RcMap<in K, out A, out E = never> extends Pipeable {
readonly [TypeId]: Variance<K, A, E>;
}

Type Ids

Since v3.5.0

Signature

declare const TypeId: unique symbol
Since v3.5.0

Signature

type TypeId = typeof TypeId