Hyperlinkv0.8.0-beta.28

RcMap

RcMap.keysconsteffect/RcMap.ts:454
<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)
combinatorshas
Source effect/RcMap.ts:4545 lines
export const keys = <K, A, E>(self: RcMap<K, A, E>): Effect.Effect<Iterable<K>> => {
  return Effect.suspend(() =>
    self.state._tag === "Closed" ? Effect.interrupt : Effect.succeed(MutableHashMap.keys(self.state.map))
  )
}