<K, A, E>(self: RcMap<K, A, E>): Effect.Effect<Iterable<K>>Returns an iterable of all keys currently stored in the RcMap.
When to use
Use to inspect which keys currently have stored resources in an RcMap.
Details
If the RcMap has been closed, the effect is interrupted.
Example (Listing keys)
import { Effect, RcMap } from "effect"
Effect.gen(function*() {
const map = yield* RcMap.make({
lookup: (key: string) => Effect.succeed(`value-${key}`)
})
// Add some resources to the map
yield* RcMap.get(map, "foo")
yield* RcMap.get(map, "bar")
yield* RcMap.get(map, "baz")
// Get all keys currently in the map
const allKeys = yield* RcMap.keys(map)
console.log(allKeys) // ["foo", "bar", "baz"]
}).pipe(Effect.scoped)export const const keys: <K, A, E>(
self: RcMap<K, A, E>
) => Effect.Effect<Iterable<K>>
Returns an iterable of all keys currently stored in the RcMap.
When to use
Use to inspect which keys currently have stored resources in an RcMap.
Details
If the RcMap has been closed, the effect is interrupted.
Example (Listing keys)
import { Effect, RcMap } from "effect"
Effect.gen(function*() {
const map = yield* RcMap.make({
lookup: (key: string) => Effect.succeed(`value-${key}`)
})
// Add some resources to the map
yield* RcMap.get(map, "foo")
yield* RcMap.get(map, "bar")
yield* RcMap.get(map, "baz")
// Get all keys currently in the map
const allKeys = yield* RcMap.keys(map)
console.log(allKeys) // ["foo", "bar", "baz"]
}).pipe(Effect.scoped)
keys = <function (type parameter) K in <K, A, E>(self: RcMap<K, A, E>): Effect.Effect<Iterable<K>>K, function (type parameter) A in <K, A, E>(self: RcMap<K, A, E>): Effect.Effect<Iterable<K>>A, function (type parameter) E in <K, A, E>(self: RcMap<K, A, E>): Effect.Effect<Iterable<K>>E>(self: RcMap<K, A, E>(parameter) 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: 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>(self: RcMap<K, A, E>): Effect.Effect<Iterable<K>>K, function (type parameter) A in <K, A, E>(self: RcMap<K, A, E>): Effect.Effect<Iterable<K>>A, function (type parameter) E in <K, A, E>(self: RcMap<K, A, E>): Effect.Effect<Iterable<K>>E>): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) K in <K, A, E>(self: RcMap<K, A, E>): Effect.Effect<Iterable<K>>K>> => {
return import EffectEffect.suspend(() =>
self: RcMap<K, A, E>(parameter) 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" ? import EffectEffect.interrupt : import EffectEffect.succeed(import MutableHashMapMutableHashMap.keys(self: RcMap<K, A, E>(parameter) 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))
)
}