Hyperlinkv0.9.0-beta.0

MutableHashMap

MutableHashMap.clearconsteffect/MutableHashMap.ts:768
<K, V>(self: MutableHashMap<K, V>): MutableHashMap<K, V>

Removes all key-value pairs from the MutableHashMap, mutating the map in place. The map becomes empty after this operation.

When to use

Use to empty a mutable hash map while keeping the same map instance.

Example (Clearing all entries)

import { MutableHashMap } from "effect"

const map = MutableHashMap.make(
  ["key1", 42],
  ["key2", 100],
  ["key3", 200]
)

console.log(MutableHashMap.size(map)) // 3

// Clear all entries
MutableHashMap.clear(map)

console.log(MutableHashMap.size(map)) // 0
console.log(MutableHashMap.has(map, "key1")) // false

// Can still add new entries after clearing
MutableHashMap.set(map, "new", 999)
console.log(MutableHashMap.size(map)) // 1
mutationsremoveempty
export const clear = <K, V>(self: MutableHashMap<K, V>) => {
  self.backing.clear()
  self.buckets.clear()
  return self
}
Referenced by 4 symbols