<K>(key: K): <A, E>(self: RcMap<K, A, E>) => Effect.Effect<boolean>
<K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<boolean>Returns whether the RcMap currently contains an entry for the specified
key.
When to use
Use to check whether a key is already present in an RcMap without running
the lookup function or acquiring a missing resource.
Details
This operation only checks the current map state.
Gotchas
Closed maps return false, so false does not distinguish a missing key
from a closed map.
export const const has: {
<K>(key: K): <A, E>(
self: RcMap<K, A, E>
) => Effect.Effect<boolean>
<K, A, E>(
self: RcMap<K, A, E>,
key: K
): Effect.Effect<boolean>
}
Returns whether the RcMap currently contains an entry for the specified
key.
When to use
Use to check whether a key is already present in an RcMap without running
the lookup function or acquiring a missing resource.
Details
This operation only checks the current map state.
Gotchas
Closed maps return false, so false does not distinguish a missing key
from a closed map.
has: {
<function (type parameter) K in <K>(key: K): <A, E>(self: RcMap<K, A, E>) => Effect.Effect<boolean>K>(key: Kkey: function (type parameter) K in <K>(key: K): <A, E>(self: RcMap<K, A, E>) => Effect.Effect<boolean>K): <function (type parameter) A in <A, E>(self: RcMap<K, A, E>): Effect.Effect<boolean>A, function (type parameter) E in <A, E>(self: RcMap<K, A, E>): Effect.Effect<boolean>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>(key: K): <A, E>(self: RcMap<K, A, E>) => Effect.Effect<boolean>K, function (type parameter) A in <A, E>(self: RcMap<K, A, E>): Effect.Effect<boolean>A, function (type parameter) E in <A, E>(self: RcMap<K, A, E>): Effect.Effect<boolean>E>) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<boolean>
<function (type parameter) K in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<boolean>K, function (type parameter) A in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<boolean>A, function (type parameter) E in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<boolean>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>, key: K): Effect.Effect<boolean>K, function (type parameter) A in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<boolean>A, function (type parameter) E in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<boolean>E>, key: Kkey: function (type parameter) K in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<boolean>K): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<boolean>
} = import dualdual(
2,
<function (type parameter) K in <K, A, E>(self: RcMap<K, A, E>, key: K): anyK, function (type parameter) A in <K, A, E>(self: RcMap<K, A, E>, key: K): anyA, function (type parameter) E in <K, A, E>(self: RcMap<K, A, E>, key: K): anyE>(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>, key: K): anyK, function (type parameter) A in <K, A, E>(self: RcMap<K, A, E>, key: K): anyA, function (type parameter) E in <K, A, E>(self: RcMap<K, A, E>, key: K): anyE>, key: Kkey: function (type parameter) K in <K, A, E>(self: RcMap<K, A, E>, key: K): anyK) =>
import EffectEffect.sync(() => {
if (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") return false
return import MutableHashMapMutableHashMap.has(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, key: Kkey)
})
)