<K1 extends K, K, V1 extends V, V>(
entries: Iterable<readonly [K1, V1]>
): (self: TxHashMap<K, V>) => Effect.Effect<void>
<K1 extends K, K, V1 extends V, V>(
self: TxHashMap<K, V>,
entries: Iterable<readonly [K1, V1]>
): Effect.Effect<void>Sets multiple key-value pairs in the TxHashMap.
Details
This function mutates the original TxHashMap by setting all provided key-value pairs. It does not return a new TxHashMap reference.
Example (Setting multiple entries)
import { Effect, TxHashMap } from "effect"
const program = Effect.gen(function*() {
// Create an empty product catalog
const catalog = yield* TxHashMap.empty<
string,
{ price: number; stock: number }
>()
// Bulk load initial products
const initialProducts: Array<
readonly [string, { price: number; stock: number }]
> = [
["laptop", { price: 999, stock: 5 }],
["mouse", { price: 29, stock: 50 }],
["keyboard", { price: 79, stock: 20 }],
["monitor", { price: 299, stock: 8 }]
]
yield* TxHashMap.setMany(catalog, initialProducts)
console.log(yield* TxHashMap.size(catalog)) // 4
// Update prices with a new batch
const priceUpdates: Array<
readonly [string, { price: number; stock: number }]
> = [
["laptop", { price: 899, stock: 5 }], // sale price
["mouse", { price: 25, stock: 50 }], // sale price
["webcam", { price: 89, stock: 12 }] // new product
]
yield* TxHashMap.setMany(catalog, priceUpdates)
console.log(yield* TxHashMap.size(catalog)) // 5 (4 original + 1 new)
// Verify the updates
const laptop = yield* TxHashMap.get(catalog, "laptop")
console.log(laptop) // Option.some({ price: 899, stock: 5 })
// Can also use Map, Set of tuples, or any iterable of entries
const jsMap = new Map([["tablet", { price: 399, stock: 3 }]])
yield* TxHashMap.setMany(catalog, jsMap)
})export const const setMany: {
<K1 extends K, K, V1 extends V, V>(
entries: Iterable<readonly [K1, V1]>
): (
self: TxHashMap<K, V>
) => Effect.Effect<void>
<K1 extends K, K, V1 extends V, V>(
self: TxHashMap<K, V>,
entries: Iterable<readonly [K1, V1]>
): Effect.Effect<void>
}
Sets multiple key-value pairs in the TxHashMap.
Details
This function mutates the original TxHashMap by setting all provided key-value
pairs. It does not return a new TxHashMap reference.
Example (Setting multiple entries)
import { Effect, TxHashMap } from "effect"
const program = Effect.gen(function*() {
// Create an empty product catalog
const catalog = yield* TxHashMap.empty<
string,
{ price: number; stock: number }
>()
// Bulk load initial products
const initialProducts: Array<
readonly [string, { price: number; stock: number }]
> = [
["laptop", { price: 999, stock: 5 }],
["mouse", { price: 29, stock: 50 }],
["keyboard", { price: 79, stock: 20 }],
["monitor", { price: 299, stock: 8 }]
]
yield* TxHashMap.setMany(catalog, initialProducts)
console.log(yield* TxHashMap.size(catalog)) // 4
// Update prices with a new batch
const priceUpdates: Array<
readonly [string, { price: number; stock: number }]
> = [
["laptop", { price: 899, stock: 5 }], // sale price
["mouse", { price: 25, stock: 50 }], // sale price
["webcam", { price: 89, stock: 12 }] // new product
]
yield* TxHashMap.setMany(catalog, priceUpdates)
console.log(yield* TxHashMap.size(catalog)) // 5 (4 original + 1 new)
// Verify the updates
const laptop = yield* TxHashMap.get(catalog, "laptop")
console.log(laptop) // Option.some({ price: 899, stock: 5 })
// Can also use Map, Set of tuples, or any iterable of entries
const jsMap = new Map([["tablet", { price: 399, stock: 3 }]])
yield* TxHashMap.setMany(catalog, jsMap)
})
setMany: {
<function (type parameter) K1 in <K1 extends K, K, V1 extends V, V>(entries: Iterable<readonly [K1, V1]>): (self: TxHashMap<K, V>) => Effect.Effect<void>K1 extends function (type parameter) K in <K1 extends K, K, V1 extends V, V>(entries: Iterable<readonly [K1, V1]>): (self: TxHashMap<K, V>) => Effect.Effect<void>K, function (type parameter) K in <K1 extends K, K, V1 extends V, V>(entries: Iterable<readonly [K1, V1]>): (self: TxHashMap<K, V>) => Effect.Effect<void>K, function (type parameter) V1 in <K1 extends K, K, V1 extends V, V>(entries: Iterable<readonly [K1, V1]>): (self: TxHashMap<K, V>) => Effect.Effect<void>V1 extends function (type parameter) V in <K1 extends K, K, V1 extends V, V>(entries: Iterable<readonly [K1, V1]>): (self: TxHashMap<K, V>) => Effect.Effect<void>V, function (type parameter) V in <K1 extends K, K, V1 extends V, V>(entries: Iterable<readonly [K1, V1]>): (self: TxHashMap<K, V>) => Effect.Effect<void>V>(
entries: Iterable<readonly [K1, V1]>entries: interface Iterable<T, TReturn = any, TNext = any>Iterable<readonly [function (type parameter) K1 in <K1 extends K, K, V1 extends V, V>(entries: Iterable<readonly [K1, V1]>): (self: TxHashMap<K, V>) => Effect.Effect<void>K1, function (type parameter) V1 in <K1 extends K, K, V1 extends V, V>(entries: Iterable<readonly [K1, V1]>): (self: TxHashMap<K, V>) => Effect.Effect<void>V1]>
): (self: TxHashMap<K, V>(parameter) self: {
ref: TxRef.TxRef<HashMap.HashMap<K, V>>;
toString: () => string;
toJSON: () => unknown;
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; <…;
}
self: interface TxHashMap<in out K, in out V>A TxHashMap is a transactional hash map data structure that provides atomic operations
on key-value pairs within Effect transactions. It uses an immutable HashMap internally
with TxRef for transactional semantics, ensuring all operations are performed atomically.
Example (Using transactional hash maps)
import { Effect, TxHashMap } from "effect"
const program = Effect.gen(function*() {
// Create a transactional hash map
const txMap = yield* TxHashMap.make(["user1", "Alice"], ["user2", "Bob"])
// Single operations are automatically transactional
yield* TxHashMap.set(txMap, "user3", "Charlie")
const user = yield* TxHashMap.get(txMap, "user1")
console.log(user) // Option.some("Alice")
// Multi-step atomic operations
yield* Effect.tx(
Effect.gen(function*() {
const currentUser = yield* TxHashMap.get(txMap, "user1")
if (currentUser._tag === "Some") {
yield* TxHashMap.set(txMap, "user1", currentUser.value + "_updated")
yield* TxHashMap.remove(txMap, "user2")
}
})
)
const size = yield* TxHashMap.size(txMap)
console.log(size) // 2
})
The TxHashMap namespace contains type-level utilities and helper types
for working with TxHashMap instances.
Example (Reusing extracted TxHashMap types)
import { Effect, TxHashMap } from "effect"
const program = Effect.gen(function*() {
// Create a transactional inventory map
const inventory = yield* TxHashMap.make(
["laptop", { stock: 5, price: 999 }],
["mouse", { stock: 20, price: 29 }]
)
// Extract types for reuse
type ProductId = TxHashMap.TxHashMap.Key<typeof inventory> // string
type Product = TxHashMap.TxHashMap.Value<typeof inventory> // { stock: number, price: number }
type InventoryEntry = TxHashMap.TxHashMap.Entry<typeof inventory> // [string, Product]
// Use extracted types in functions
const updateStock = (id: ProductId, newStock: number) =>
TxHashMap.modify(
inventory,
id,
(product) => ({ ...product, stock: newStock })
)
yield* updateStock("laptop", 3)
})
TxHashMap<function (type parameter) K in <K1 extends K, K, V1 extends V, V>(entries: Iterable<readonly [K1, V1]>): (self: TxHashMap<K, V>) => Effect.Effect<void>K, function (type parameter) V in <K1 extends K, K, V1 extends V, V>(entries: Iterable<readonly [K1, V1]>): (self: TxHashMap<K, V>) => Effect.Effect<void>V>) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<void>
<function (type parameter) K1 in <K1 extends K, K, V1 extends V, V>(self: TxHashMap<K, V>, entries: Iterable<readonly [K1, V1]>): Effect.Effect<void>K1 extends function (type parameter) K in <K1 extends K, K, V1 extends V, V>(self: TxHashMap<K, V>, entries: Iterable<readonly [K1, V1]>): Effect.Effect<void>K, function (type parameter) K in <K1 extends K, K, V1 extends V, V>(self: TxHashMap<K, V>, entries: Iterable<readonly [K1, V1]>): Effect.Effect<void>K, function (type parameter) V1 in <K1 extends K, K, V1 extends V, V>(self: TxHashMap<K, V>, entries: Iterable<readonly [K1, V1]>): Effect.Effect<void>V1 extends function (type parameter) V in <K1 extends K, K, V1 extends V, V>(self: TxHashMap<K, V>, entries: Iterable<readonly [K1, V1]>): Effect.Effect<void>V, function (type parameter) V in <K1 extends K, K, V1 extends V, V>(self: TxHashMap<K, V>, entries: Iterable<readonly [K1, V1]>): Effect.Effect<void>V>(
self: TxHashMap<K, V>(parameter) self: {
ref: TxRef.TxRef<HashMap.HashMap<K, V>>;
toString: () => string;
toJSON: () => unknown;
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; <…;
}
self: interface TxHashMap<in out K, in out V>A TxHashMap is a transactional hash map data structure that provides atomic operations
on key-value pairs within Effect transactions. It uses an immutable HashMap internally
with TxRef for transactional semantics, ensuring all operations are performed atomically.
Example (Using transactional hash maps)
import { Effect, TxHashMap } from "effect"
const program = Effect.gen(function*() {
// Create a transactional hash map
const txMap = yield* TxHashMap.make(["user1", "Alice"], ["user2", "Bob"])
// Single operations are automatically transactional
yield* TxHashMap.set(txMap, "user3", "Charlie")
const user = yield* TxHashMap.get(txMap, "user1")
console.log(user) // Option.some("Alice")
// Multi-step atomic operations
yield* Effect.tx(
Effect.gen(function*() {
const currentUser = yield* TxHashMap.get(txMap, "user1")
if (currentUser._tag === "Some") {
yield* TxHashMap.set(txMap, "user1", currentUser.value + "_updated")
yield* TxHashMap.remove(txMap, "user2")
}
})
)
const size = yield* TxHashMap.size(txMap)
console.log(size) // 2
})
The TxHashMap namespace contains type-level utilities and helper types
for working with TxHashMap instances.
Example (Reusing extracted TxHashMap types)
import { Effect, TxHashMap } from "effect"
const program = Effect.gen(function*() {
// Create a transactional inventory map
const inventory = yield* TxHashMap.make(
["laptop", { stock: 5, price: 999 }],
["mouse", { stock: 20, price: 29 }]
)
// Extract types for reuse
type ProductId = TxHashMap.TxHashMap.Key<typeof inventory> // string
type Product = TxHashMap.TxHashMap.Value<typeof inventory> // { stock: number, price: number }
type InventoryEntry = TxHashMap.TxHashMap.Entry<typeof inventory> // [string, Product]
// Use extracted types in functions
const updateStock = (id: ProductId, newStock: number) =>
TxHashMap.modify(
inventory,
id,
(product) => ({ ...product, stock: newStock })
)
yield* updateStock("laptop", 3)
})
TxHashMap<function (type parameter) K in <K1 extends K, K, V1 extends V, V>(self: TxHashMap<K, V>, entries: Iterable<readonly [K1, V1]>): Effect.Effect<void>K, function (type parameter) V in <K1 extends K, K, V1 extends V, V>(self: TxHashMap<K, V>, entries: Iterable<readonly [K1, V1]>): Effect.Effect<void>V>,
entries: Iterable<readonly [K1, V1]>entries: interface Iterable<T, TReturn = any, TNext = any>Iterable<readonly [function (type parameter) K1 in <K1 extends K, K, V1 extends V, V>(self: TxHashMap<K, V>, entries: Iterable<readonly [K1, V1]>): Effect.Effect<void>K1, function (type parameter) V1 in <K1 extends K, K, V1 extends V, V>(self: TxHashMap<K, V>, entries: Iterable<readonly [K1, V1]>): Effect.Effect<void>V1]>
): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<void>
} = import dualdual(
2,
<function (type parameter) K1 in <K1 extends K, K, V1 extends V, V>(self: TxHashMap<K, V>, entries: Iterable<readonly [K1, V1]>): Effect.Effect<void>K1 extends function (type parameter) K in <K1 extends K, K, V1 extends V, V>(self: TxHashMap<K, V>, entries: Iterable<readonly [K1, V1]>): Effect.Effect<void>K, function (type parameter) K in <K1 extends K, K, V1 extends V, V>(self: TxHashMap<K, V>, entries: Iterable<readonly [K1, V1]>): Effect.Effect<void>K, function (type parameter) V1 in <K1 extends K, K, V1 extends V, V>(self: TxHashMap<K, V>, entries: Iterable<readonly [K1, V1]>): Effect.Effect<void>V1 extends function (type parameter) V in <K1 extends K, K, V1 extends V, V>(self: TxHashMap<K, V>, entries: Iterable<readonly [K1, V1]>): Effect.Effect<void>V, function (type parameter) V in <K1 extends K, K, V1 extends V, V>(self: TxHashMap<K, V>, entries: Iterable<readonly [K1, V1]>): Effect.Effect<void>V>(
self: TxHashMap<K, V>(parameter) self: {
ref: TxRef.TxRef<HashMap.HashMap<K, V>>;
toString: () => string;
toJSON: () => unknown;
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; <…;
}
self: interface TxHashMap<in out K, in out V>A TxHashMap is a transactional hash map data structure that provides atomic operations
on key-value pairs within Effect transactions. It uses an immutable HashMap internally
with TxRef for transactional semantics, ensuring all operations are performed atomically.
Example (Using transactional hash maps)
import { Effect, TxHashMap } from "effect"
const program = Effect.gen(function*() {
// Create a transactional hash map
const txMap = yield* TxHashMap.make(["user1", "Alice"], ["user2", "Bob"])
// Single operations are automatically transactional
yield* TxHashMap.set(txMap, "user3", "Charlie")
const user = yield* TxHashMap.get(txMap, "user1")
console.log(user) // Option.some("Alice")
// Multi-step atomic operations
yield* Effect.tx(
Effect.gen(function*() {
const currentUser = yield* TxHashMap.get(txMap, "user1")
if (currentUser._tag === "Some") {
yield* TxHashMap.set(txMap, "user1", currentUser.value + "_updated")
yield* TxHashMap.remove(txMap, "user2")
}
})
)
const size = yield* TxHashMap.size(txMap)
console.log(size) // 2
})
The TxHashMap namespace contains type-level utilities and helper types
for working with TxHashMap instances.
Example (Reusing extracted TxHashMap types)
import { Effect, TxHashMap } from "effect"
const program = Effect.gen(function*() {
// Create a transactional inventory map
const inventory = yield* TxHashMap.make(
["laptop", { stock: 5, price: 999 }],
["mouse", { stock: 20, price: 29 }]
)
// Extract types for reuse
type ProductId = TxHashMap.TxHashMap.Key<typeof inventory> // string
type Product = TxHashMap.TxHashMap.Value<typeof inventory> // { stock: number, price: number }
type InventoryEntry = TxHashMap.TxHashMap.Entry<typeof inventory> // [string, Product]
// Use extracted types in functions
const updateStock = (id: ProductId, newStock: number) =>
TxHashMap.modify(
inventory,
id,
(product) => ({ ...product, stock: newStock })
)
yield* updateStock("laptop", 3)
})
TxHashMap<function (type parameter) K in <K1 extends K, K, V1 extends V, V>(self: TxHashMap<K, V>, entries: Iterable<readonly [K1, V1]>): Effect.Effect<void>K, function (type parameter) V in <K1 extends K, K, V1 extends V, V>(self: TxHashMap<K, V>, entries: Iterable<readonly [K1, V1]>): Effect.Effect<void>V>,
entries: Iterable<readonly [K1, V1]>entries: interface Iterable<T, TReturn = any, TNext = any>Iterable<readonly [function (type parameter) K1 in <K1 extends K, K, V1 extends V, V>(self: TxHashMap<K, V>, entries: Iterable<readonly [K1, V1]>): Effect.Effect<void>K1, function (type parameter) V1 in <K1 extends K, K, V1 extends V, V>(self: TxHashMap<K, V>, entries: Iterable<readonly [K1, V1]>): Effect.Effect<void>V1]>
): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<void> => import TxRefTxRef.const update: {
<A>(f: (current: NoInfer<A>) => A): (
self: TxRef<A>
) => Effect.Effect<void>
<A>(
self: TxRef<A>,
f: (current: A) => A
): Effect.Effect<void>
}
update(self: TxHashMap<K, V>(parameter) self: {
ref: TxRef.TxRef<HashMap.HashMap<K, V>>;
toString: () => string;
toJSON: () => unknown;
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; <…;
}
self.TxHashMap<in out K, in out V>.ref: TxRef.TxRef<HashMap.HashMap<K, V>>(property) TxHashMap<in out K, in out V>.ref: {
version: number;
pending: Map<unknown, () => void>;
value: A;
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; <…;
}
ref, (map: HashMap.HashMap<K, V>(parameter) map: {
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;
}
map) => import HashMapHashMap.setMany(map: HashMap.HashMap<K, V>(parameter) map: {
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;
}
map, entries: Iterable<readonly [K1, V1]>entries))
)