<K, V>(key: K, f: HashMap.UpdateFn<V>): (
self: HashMap<K, V>
) => HashMap<K, V>
<K, V>(self: HashMap<K, V>, key: K, f: HashMap.UpdateFn<V>): HashMap<K, V>Sets or removes the specified key using an update function.
Details
The update function receives Some(value) when the key exists or None
when it does not. Returning Some(newValue) stores the value, and returning
None removes the key or leaves it absent.
Example (Updating values with Options)
import { HashMap, Option } from "effect"
const map = HashMap.make(["a", 1], ["b", 2])
// Increment existing value or set to 1 if not present
const updateFn = (option: Option.Option<number>) =>
Option.isSome(option) ? Option.some(option.value + 1) : Option.some(1)
const updated = HashMap.modifyAt(map, "a", updateFn)
console.log(HashMap.get(updated, "a")) // Option.some(2)export const const modifyAt: {
<K, V>(key: K, f: HashMap.UpdateFn<V>): (
self: HashMap<K, V>
) => HashMap<K, V>
<K, V>(
self: HashMap<K, V>,
key: K,
f: HashMap.UpdateFn<V>
): HashMap<K, V>
}
Sets or removes the specified key using an update function.
Details
The update function receives Some(value) when the key exists or None
when it does not. Returning Some(newValue) stores the value, and returning
None removes the key or leaves it absent.
Example (Updating values with Options)
import { HashMap, Option } from "effect"
const map = HashMap.make(["a", 1], ["b", 2])
// Increment existing value or set to 1 if not present
const updateFn = (option: Option.Option<number>) =>
Option.isSome(option) ? Option.some(option.value + 1) : Option.some(1)
const updated = HashMap.modifyAt(map, "a", updateFn)
console.log(HashMap.get(updated, "a")) // Option.some(2)
modifyAt: {
<function (type parameter) K in <K, V>(key: K, f: HashMap.UpdateFn<V>): (self: HashMap<K, V>) => HashMap<K, V>K, function (type parameter) V in <K, V>(key: K, f: HashMap.UpdateFn<V>): (self: HashMap<K, V>) => HashMap<K, V>V>(key: Kkey: function (type parameter) K in <K, V>(key: K, f: HashMap.UpdateFn<V>): (self: HashMap<K, V>) => HashMap<K, V>K, f: HashMap.UpdateFn<V>f: HashMap.type HashMap<out Key, out Value>.UpdateFn<V> = (option: Option<V>) => Option<V>A function that updates a value based on its current state.
Takes an Option representing the current value and returns an Option
representing the new value.
Example (Updating values from Options)
import { HashMap, Option } from "effect"
const map = HashMap.make(["a", 1], ["b", 2])
// Increment existing value or set to 1 if not present
const updateFn = (option: Option.Option<number>) =>
Option.isSome(option) ? Option.some(option.value + 1) : Option.some(1)
const updated = HashMap.modifyAt(map, "a", updateFn)
console.log(HashMap.get(updated, "a")) // Option.some(2)
UpdateFn<function (type parameter) V in <K, V>(key: K, f: HashMap.UpdateFn<V>): (self: HashMap<K, V>) => HashMap<K, V>V>): (self: HashMap<K, V>(parameter) self: {
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 HashMap<out Key, out Value>A HashMap is an immutable key-value data structure that provides efficient lookup,
insertion, and deletion operations. It uses a Hash Array Mapped Trie (HAMT) internally
for structural sharing and optimal performance.
Example (Using basic HashMap operations)
import { HashMap } from "effect"
// Create a HashMap
const map = HashMap.make(["a", 1], ["b", 2], ["c", 3])
// Access values
const valueA = HashMap.get(map, "a") // Option.some(1)
const valueD = HashMap.get(map, "d") // Option.none()
// Check if key exists
console.log(HashMap.has(map, "b")) // true
// Add/update values (returns new HashMap)
const updated = HashMap.set(map, "d", 4)
console.log(HashMap.size(updated)) // 4
The HashMap namespace contains type-level utilities and helper types
for working with HashMap instances.
Example (Extracting HashMap types)
import { HashMap } from "effect"
// Create a concrete HashMap for type extraction
const inventory = HashMap.make(
["laptop", { quantity: 5, price: 999 }],
["mouse", { quantity: 20, price: 29 }]
)
// Extract types for reuse
type ProductId = HashMap.HashMap.Key<typeof inventory> // string
type Product = HashMap.HashMap.Value<typeof inventory> // { quantity: number, price: number }
type InventoryEntry = HashMap.HashMap.Entry<typeof inventory> // [string, Product]
// Use extracted types in functions
const updateInventory = (id: ProductId, product: Product) =>
HashMap.set(inventory, id, product)
const processEntry = ([id, product]: InventoryEntry) =>
`${id}: ${product.quantity} @ $${product.price}`
// Example of extracted types in action
const newProduct: Product = { quantity: 10, price: 199 }
const updatedInventory = updateInventory("tablet", newProduct)
HashMap<function (type parameter) K in <K, V>(key: K, f: HashMap.UpdateFn<V>): (self: HashMap<K, V>) => HashMap<K, V>K, function (type parameter) V in <K, V>(key: K, f: HashMap.UpdateFn<V>): (self: HashMap<K, V>) => HashMap<K, V>V>) => interface HashMap<out Key, out Value>A HashMap is an immutable key-value data structure that provides efficient lookup,
insertion, and deletion operations. It uses a Hash Array Mapped Trie (HAMT) internally
for structural sharing and optimal performance.
Example (Using basic HashMap operations)
import { HashMap } from "effect"
// Create a HashMap
const map = HashMap.make(["a", 1], ["b", 2], ["c", 3])
// Access values
const valueA = HashMap.get(map, "a") // Option.some(1)
const valueD = HashMap.get(map, "d") // Option.none()
// Check if key exists
console.log(HashMap.has(map, "b")) // true
// Add/update values (returns new HashMap)
const updated = HashMap.set(map, "d", 4)
console.log(HashMap.size(updated)) // 4
The HashMap namespace contains type-level utilities and helper types
for working with HashMap instances.
Example (Extracting HashMap types)
import { HashMap } from "effect"
// Create a concrete HashMap for type extraction
const inventory = HashMap.make(
["laptop", { quantity: 5, price: 999 }],
["mouse", { quantity: 20, price: 29 }]
)
// Extract types for reuse
type ProductId = HashMap.HashMap.Key<typeof inventory> // string
type Product = HashMap.HashMap.Value<typeof inventory> // { quantity: number, price: number }
type InventoryEntry = HashMap.HashMap.Entry<typeof inventory> // [string, Product]
// Use extracted types in functions
const updateInventory = (id: ProductId, product: Product) =>
HashMap.set(inventory, id, product)
const processEntry = ([id, product]: InventoryEntry) =>
`${id}: ${product.quantity} @ $${product.price}`
// Example of extracted types in action
const newProduct: Product = { quantity: 10, price: 199 }
const updatedInventory = updateInventory("tablet", newProduct)
HashMap<function (type parameter) K in <K, V>(key: K, f: HashMap.UpdateFn<V>): (self: HashMap<K, V>) => HashMap<K, V>K, function (type parameter) V in <K, V>(key: K, f: HashMap.UpdateFn<V>): (self: HashMap<K, V>) => HashMap<K, V>V>
<function (type parameter) K in <K, V>(self: HashMap<K, V>, key: K, f: HashMap.UpdateFn<V>): HashMap<K, V>K, function (type parameter) V in <K, V>(self: HashMap<K, V>, key: K, f: HashMap.UpdateFn<V>): HashMap<K, V>V>(self: HashMap<K, V>(parameter) self: {
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 HashMap<out Key, out Value>A HashMap is an immutable key-value data structure that provides efficient lookup,
insertion, and deletion operations. It uses a Hash Array Mapped Trie (HAMT) internally
for structural sharing and optimal performance.
Example (Using basic HashMap operations)
import { HashMap } from "effect"
// Create a HashMap
const map = HashMap.make(["a", 1], ["b", 2], ["c", 3])
// Access values
const valueA = HashMap.get(map, "a") // Option.some(1)
const valueD = HashMap.get(map, "d") // Option.none()
// Check if key exists
console.log(HashMap.has(map, "b")) // true
// Add/update values (returns new HashMap)
const updated = HashMap.set(map, "d", 4)
console.log(HashMap.size(updated)) // 4
The HashMap namespace contains type-level utilities and helper types
for working with HashMap instances.
Example (Extracting HashMap types)
import { HashMap } from "effect"
// Create a concrete HashMap for type extraction
const inventory = HashMap.make(
["laptop", { quantity: 5, price: 999 }],
["mouse", { quantity: 20, price: 29 }]
)
// Extract types for reuse
type ProductId = HashMap.HashMap.Key<typeof inventory> // string
type Product = HashMap.HashMap.Value<typeof inventory> // { quantity: number, price: number }
type InventoryEntry = HashMap.HashMap.Entry<typeof inventory> // [string, Product]
// Use extracted types in functions
const updateInventory = (id: ProductId, product: Product) =>
HashMap.set(inventory, id, product)
const processEntry = ([id, product]: InventoryEntry) =>
`${id}: ${product.quantity} @ $${product.price}`
// Example of extracted types in action
const newProduct: Product = { quantity: 10, price: 199 }
const updatedInventory = updateInventory("tablet", newProduct)
HashMap<function (type parameter) K in <K, V>(self: HashMap<K, V>, key: K, f: HashMap.UpdateFn<V>): HashMap<K, V>K, function (type parameter) V in <K, V>(self: HashMap<K, V>, key: K, f: HashMap.UpdateFn<V>): HashMap<K, V>V>, key: Kkey: function (type parameter) K in <K, V>(self: HashMap<K, V>, key: K, f: HashMap.UpdateFn<V>): HashMap<K, V>K, f: HashMap.UpdateFn<V>f: HashMap.type HashMap<out Key, out Value>.UpdateFn<V> = (option: Option<V>) => Option<V>A function that updates a value based on its current state.
Takes an Option representing the current value and returns an Option
representing the new value.
Example (Updating values from Options)
import { HashMap, Option } from "effect"
const map = HashMap.make(["a", 1], ["b", 2])
// Increment existing value or set to 1 if not present
const updateFn = (option: Option.Option<number>) =>
Option.isSome(option) ? Option.some(option.value + 1) : Option.some(1)
const updated = HashMap.modifyAt(map, "a", updateFn)
console.log(HashMap.get(updated, "a")) // Option.some(2)
UpdateFn<function (type parameter) V in <K, V>(self: HashMap<K, V>, key: K, f: HashMap.UpdateFn<V>): HashMap<K, V>V>): interface HashMap<out Key, out Value>A HashMap is an immutable key-value data structure that provides efficient lookup,
insertion, and deletion operations. It uses a Hash Array Mapped Trie (HAMT) internally
for structural sharing and optimal performance.
Example (Using basic HashMap operations)
import { HashMap } from "effect"
// Create a HashMap
const map = HashMap.make(["a", 1], ["b", 2], ["c", 3])
// Access values
const valueA = HashMap.get(map, "a") // Option.some(1)
const valueD = HashMap.get(map, "d") // Option.none()
// Check if key exists
console.log(HashMap.has(map, "b")) // true
// Add/update values (returns new HashMap)
const updated = HashMap.set(map, "d", 4)
console.log(HashMap.size(updated)) // 4
The HashMap namespace contains type-level utilities and helper types
for working with HashMap instances.
Example (Extracting HashMap types)
import { HashMap } from "effect"
// Create a concrete HashMap for type extraction
const inventory = HashMap.make(
["laptop", { quantity: 5, price: 999 }],
["mouse", { quantity: 20, price: 29 }]
)
// Extract types for reuse
type ProductId = HashMap.HashMap.Key<typeof inventory> // string
type Product = HashMap.HashMap.Value<typeof inventory> // { quantity: number, price: number }
type InventoryEntry = HashMap.HashMap.Entry<typeof inventory> // [string, Product]
// Use extracted types in functions
const updateInventory = (id: ProductId, product: Product) =>
HashMap.set(inventory, id, product)
const processEntry = ([id, product]: InventoryEntry) =>
`${id}: ${product.quantity} @ $${product.price}`
// Example of extracted types in action
const newProduct: Product = { quantity: 10, price: 199 }
const updatedInventory = updateInventory("tablet", newProduct)
HashMap<function (type parameter) K in <K, V>(self: HashMap<K, V>, key: K, f: HashMap.UpdateFn<V>): HashMap<K, V>K, function (type parameter) V in <K, V>(self: HashMap<K, V>, key: K, f: HashMap.UpdateFn<V>): HashMap<K, V>V>
} = import internalinternal.const modifyAt: anymodifyAt