<K, V>(f: (value: V, key: K) => void): (
self: MutableHashMap<K, V>
) => void
<K, V>(self: MutableHashMap<K, V>, f: (value: V, key: K) => void): voidRuns a callback for each key-value pair in the MutableHashMap.
When to use
Use to run a synchronous side-effecting callback for every key-value pair in an existing mutable map.
Details
Iteration follows the backing map's order. The callback receives the value
first and the key second, matching Map.prototype.forEach.
export const const forEach: {
<K, V>(f: (value: V, key: K) => void): (
self: MutableHashMap<K, V>
) => void
<K, V>(
self: MutableHashMap<K, V>,
f: (value: V, key: K) => void
): void
}
Runs a callback for each key-value pair in the MutableHashMap.
When to use
Use to run a synchronous side-effecting callback for every key-value pair in
an existing mutable map.
Details
Iteration follows the backing map's order. The callback receives the value
first and the key second, matching Map.prototype.forEach.
forEach: {
<function (type parameter) K in <K, V>(f: (value: V, key: K) => void): (self: MutableHashMap<K, V>) => voidK, function (type parameter) V in <K, V>(f: (value: V, key: K) => void): (self: MutableHashMap<K, V>) => voidV>(f: (value: V, key: K) => voidf: (value: Vvalue: function (type parameter) V in <K, V>(f: (value: V, key: K) => void): (self: MutableHashMap<K, V>) => voidV, key: Kkey: function (type parameter) K in <K, V>(f: (value: V, key: K) => void): (self: MutableHashMap<K, V>) => voidK) => void): (self: MutableHashMap<K, V>(parameter) self: {
backing: Map<K, V>;
buckets: Map<number, NonEmptyArray<K>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self: interface MutableHashMap<out K, out V>A mutable hash map that stores key-value pairs and supports both referential
and Effect structural equality.
When to use
Use as a mutable key-value map when in-place updates are acceptable and keys
may rely on Effect structural equality.
Details
Operations mutate the map in place. Keys that implement Equal / Hash can
be looked up structurally; other keys use normal JavaScript reference or
primitive equality.
Example (Using a mutable hash map)
import { MutableHashMap } from "effect"
// Create a mutable hash map with string keys and number values
const map: MutableHashMap.MutableHashMap<string, number> = MutableHashMap
.empty()
// Add some data
MutableHashMap.set(map, "count", 42)
MutableHashMap.set(map, "total", 100)
// Use as iterable
for (const [key, value] of map) {
console.log(`${key}: ${value}`)
}
// Output:
// count: 42
// total: 100
// Convert to array
const entries = Array.from(map)
console.log(entries) // [["count", 42], ["total", 100]]
MutableHashMap<function (type parameter) K in <K, V>(f: (value: V, key: K) => void): (self: MutableHashMap<K, V>) => voidK, function (type parameter) V in <K, V>(f: (value: V, key: K) => void): (self: MutableHashMap<K, V>) => voidV>) => void
<function (type parameter) K in <K, V>(self: MutableHashMap<K, V>, f: (value: V, key: K) => void): voidK, function (type parameter) V in <K, V>(self: MutableHashMap<K, V>, f: (value: V, key: K) => void): voidV>(self: MutableHashMap<K, V>(parameter) self: {
backing: Map<K, V>;
buckets: Map<number, NonEmptyArray<K>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self: interface MutableHashMap<out K, out V>A mutable hash map that stores key-value pairs and supports both referential
and Effect structural equality.
When to use
Use as a mutable key-value map when in-place updates are acceptable and keys
may rely on Effect structural equality.
Details
Operations mutate the map in place. Keys that implement Equal / Hash can
be looked up structurally; other keys use normal JavaScript reference or
primitive equality.
Example (Using a mutable hash map)
import { MutableHashMap } from "effect"
// Create a mutable hash map with string keys and number values
const map: MutableHashMap.MutableHashMap<string, number> = MutableHashMap
.empty()
// Add some data
MutableHashMap.set(map, "count", 42)
MutableHashMap.set(map, "total", 100)
// Use as iterable
for (const [key, value] of map) {
console.log(`${key}: ${value}`)
}
// Output:
// count: 42
// total: 100
// Convert to array
const entries = Array.from(map)
console.log(entries) // [["count", 42], ["total", 100]]
MutableHashMap<function (type parameter) K in <K, V>(self: MutableHashMap<K, V>, f: (value: V, key: K) => void): voidK, function (type parameter) V in <K, V>(self: MutableHashMap<K, V>, f: (value: V, key: K) => void): voidV>, f: (value: V, key: K) => voidf: (value: Vvalue: function (type parameter) V in <K, V>(self: MutableHashMap<K, V>, f: (value: V, key: K) => void): voidV, key: Kkey: function (type parameter) K in <K, V>(self: MutableHashMap<K, V>, f: (value: V, key: K) => void): voidK) => void): void
} = dual<(...args: Array<any>) => any, <K, V>(self: MutableHashMap<K, V>, f: (value: V, key: K) => void) => void>(arity: 2, body: <K, V>(self: MutableHashMap<K, V>, f: (value: V, key: K) => void) => void): ((...args: Array<any>) => any) & (<K, V>(self: MutableHashMap<K, V>, f: (value: V, key: K) => void) => void) (+1 overload)Creates a function that can be called in data-first style or data-last
(pipe-friendly) style.
When to use
Use to expose one implementation through both direct and pipe-friendly
call styles.
Details
Pass either the arity of the uncurried function or a predicate that decides
whether the current call is data-first. Arity is the common case. Use a
predicate when optional arguments make arity ambiguous.
Example (Selecting data-first or data-last style by arity)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(2, (self, that) => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Defining overloads with call signatures)
import { Function, pipe } from "effect"
const sum: {
(that: number): (self: number) => number
(self: number, that: number): number
} = Function.dual(2, (self: number, that: number): number => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Selecting data-first or data-last style with a predicate)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(
(args) => args.length === 2,
(self, that) => self + that
)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
dual(2, <function (type parameter) K in <K, V>(self: MutableHashMap<K, V>, f: (value: V, key: K) => void): voidK, function (type parameter) V in <K, V>(self: MutableHashMap<K, V>, f: (value: V, key: K) => void): voidV>(self: MutableHashMap<K, V>(parameter) self: {
backing: Map<K, V>;
buckets: Map<number, NonEmptyArray<K>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self: interface MutableHashMap<out K, out V>A mutable hash map that stores key-value pairs and supports both referential
and Effect structural equality.
When to use
Use as a mutable key-value map when in-place updates are acceptable and keys
may rely on Effect structural equality.
Details
Operations mutate the map in place. Keys that implement Equal / Hash can
be looked up structurally; other keys use normal JavaScript reference or
primitive equality.
Example (Using a mutable hash map)
import { MutableHashMap } from "effect"
// Create a mutable hash map with string keys and number values
const map: MutableHashMap.MutableHashMap<string, number> = MutableHashMap
.empty()
// Add some data
MutableHashMap.set(map, "count", 42)
MutableHashMap.set(map, "total", 100)
// Use as iterable
for (const [key, value] of map) {
console.log(`${key}: ${value}`)
}
// Output:
// count: 42
// total: 100
// Convert to array
const entries = Array.from(map)
console.log(entries) // [["count", 42], ["total", 100]]
MutableHashMap<function (type parameter) K in <K, V>(self: MutableHashMap<K, V>, f: (value: V, key: K) => void): voidK, function (type parameter) V in <K, V>(self: MutableHashMap<K, V>, f: (value: V, key: K) => void): voidV>, f: (value: V, key: K) => voidf: (value: Vvalue: function (type parameter) V in <K, V>(self: MutableHashMap<K, V>, f: (value: V, key: K) => void): voidV, key: Kkey: function (type parameter) K in <K, V>(self: MutableHashMap<K, V>, f: (value: V, key: K) => void): voidK) => void) => {
self: MutableHashMap<K, V>(parameter) self: {
backing: Map<K, V>;
buckets: Map<number, NonEmptyArray<K>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self.MutableHashMap<K, V>.backing: Map<K, V>backing.Map<K, V>.forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): voidExecutes a provided function once per each key/value pair in the Map, in insertion order.
forEach(f: (value: V, key: K) => voidf)
})