effect-io-ai

Package: effect
Module: TxHashMap

TxHashMap.keys

Returns an array of all keys in the TxHashMap.

Example (Reading keys)

import { Effect, Option, TxHashMap } from "effect"

const program = Effect.gen(function*() {
  const userRoles = yield* TxHashMap.make(
    ["alice", "admin"],
    ["bob", "user"],
    ["charlie", "moderator"]
  )

  const usernames = yield* TxHashMap.keys(userRoles)
  console.log(usernames.sort()) // ["alice", "bob", "charlie"]

  // Useful for iteration
  for (const username of usernames) {
    const role = yield* TxHashMap.get(userRoles, username)
    if (role._tag === "Some") {
      console.log(`${username}: ${role.value}`)
    }
  }
})

Signature

declare const keys: <K, V>(self: TxHashMap<K, V>) => Effect.Effect<Array<K>>

Source

Since v2.0.0