Hyperlinkv0.8.0-beta.28

MutableHashMap

MutableHashMap.fromIterableconsteffect/MutableHashMap.ts:230
<K, V>(entries: Iterable<readonly [K, V]>): MutableHashMap<K, V>

Creates a MutableHashMap from an iterable collection of key-value pairs.

When to use

Use to create a mutable hash map from an existing iterable of entries.

Example (Creating a map from an iterable)

import { MutableHashMap } from "effect"

const entries = [
  ["apple", 1],
  ["banana", 2],
  ["cherry", 3]
] as const

const map = MutableHashMap.fromIterable(entries)

console.log(MutableHashMap.get(map, "banana")) // Some(2)
console.log(MutableHashMap.size(map)) // 3

// Works with any iterable
const fromMap = MutableHashMap.fromIterable(new Map([["x", 10], ["y", 20]]))
console.log(MutableHashMap.get(fromMap, "x")) // Some(10)
constructorsmakeempty
export const fromIterable = <K, V>(entries: Iterable<readonly [K, V]>): MutableHashMap<K, V> => {
  const self = empty<K, V>()
  for (const [key, value] of entries) {
    set(self, key, value)
  }
  return self
}
Referenced by 2 symbols