effect-io-ai

Package: effect
Module: MutableHashMap

MutableHashMap.clear

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

See

Signature

declare const clear: <K, V>(self: MutableHashMap<K, V>) => MutableHashMap<K, V>

Source

Since v2.0.0