Hyperlinkv0.8.0-beta.28

TxHashMap

TxHashMap.toValuesconsteffect/TxHashMap.ts:2156
<K, V>(self: TxHashMap<K, V>): Effect.Effect<Array<V>>

Returns an array of all values in the TxHashMap. This is an alias for the values function, providing API consistency with HashMap.

Example (Converting to values)

import { Effect, TxHashMap } from "effect"

const program = Effect.gen(function*() {
  const inventory = yield* TxHashMap.make(
    ["laptop", { price: 999, stock: 5 }],
    ["mouse", { price: 29, stock: 50 }],
    ["keyboard", { price: 79, stock: 20 }]
  )

  // Get all product information
  const products = yield* TxHashMap.toValues(inventory)
  console.log(products.length) // 3

  // Calculate total inventory value
  const totalValue = products.reduce(
    (sum, product) => sum + (product.price * product.stock),
    0
  )
  console.log(`Total inventory value: $${totalValue}`) // Total inventory value: $8025

  // Find products with low stock
  const lowStockProducts = products.filter((product) => product.stock < 10)
  console.log(`${lowStockProducts.length} product with low stock`) // 1 product with low stock
})
combinators
export const toValues = <K, V>(self: TxHashMap<K, V>): Effect.Effect<Array<V>> => values(self)