Hyperlinkv0.8.0-beta.28

TxHashMap

TxHashMap.valuesconsteffect/TxHashMap.ts:898
<K, V>(self: TxHashMap<K, V>): Effect.Effect<Array<V>>

Returns an array of all values in the TxHashMap.

Example (Reading values)

import { Effect, TxHashMap } from "effect"

const program = Effect.gen(function*() {
  const scores = yield* TxHashMap.make(
    ["alice", 95],
    ["bob", 87],
    ["charlie", 92]
  )

  const allScores = yield* TxHashMap.values(scores)
  console.log(allScores.sort((a, b) => a - b)) // [87, 92, 95]

  // Calculate average
  const average = allScores.reduce((sum, score) => sum + score, 0) /
    allScores.length
  console.log(average.toFixed(2)) // "91.33"

  // Find maximum
  const maxScore = Math.max(...allScores)
  console.log(maxScore) // 95
})
combinators
export const values = <K, V>(self: TxHashMap<K, V>): Effect.Effect<Array<V>> =>
  Effect.gen(function*() {
    const map = yield* TxRef.get(self.ref)
    return HashMap.toValues(map)
  })
Referenced by 1 symbols