RcMap
Combinators
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>;};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>;};invalidate
Added in v3.13.0
Source
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>;};Signature
declare const keys: <K, A, E>(self: RcMap<K, A, E>) => Effect.Effect<Array<K>>;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
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)})Signature
interface RcMap<in K, out A, out E = never> extends Pipeable { readonly [TypeId]: Variance<K, A, E>;}
An
RcMapcan contain multiple reference counted resources that can be indexed by a key. The resources are lazily acquired on the first call togetand released when the last reference is released.Complex keys can extend
EqualandHashto 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.