<K, A>(predicate: (a: NoInfer<A>, k: K) => boolean): (
self: HashMap<K, A>
) => boolean
<K, A>(self: HashMap<K, A>, predicate: (a: A, k: K) => boolean): booleanChecks whether all entries in a hashmap meets a specific condition.
Example (Checking all entries)
import { HashMap } from "effect"
const map = HashMap.make(["a", 1], ["b", 2], ["c", 3])
console.log(HashMap.every(map, (value) => value > 0)) // true
console.log(HashMap.every(map, (value) => value > 1)) // falseexport const const every: {
<K, A>(
predicate: (a: NoInfer<A>, k: K) => boolean
): (self: HashMap<K, A>) => boolean
<K, A>(
self: HashMap<K, A>,
predicate: (a: A, k: K) => boolean
): boolean
}
Checks whether all entries in a hashmap meets a specific condition.
Example (Checking all entries)
import { HashMap } from "effect"
const map = HashMap.make(["a", 1], ["b", 2], ["c", 3])
console.log(HashMap.every(map, (value) => value > 0)) // true
console.log(HashMap.every(map, (value) => value > 1)) // false
every: {
<function (type parameter) K in <K, A>(predicate: (a: NoInfer<A>, k: K) => boolean): (self: HashMap<K, A>) => booleanK, function (type parameter) A in <K, A>(predicate: (a: NoInfer<A>, k: K) => boolean): (self: HashMap<K, A>) => booleanA>(predicate: (a: NoInfer<A>, k: K) => booleanpredicate: (a: NoInfer<A>a: type NoInfer<A> = [A][A extends any ? 0 : never]Prevents TypeScript from inferring a type parameter from a specific
position.
When to use
Use when a function parameter must match an inferred type without becoming
an inference source.
Details
The parameter using NoInfer must still match the inferred type.
Example (Controlling inference)
import type { Types } from "effect"
declare function withDefault<T>(value: T, fallback: Types.NoInfer<T>): T
// T is inferred as "a" | "b" from the first argument only
const result = withDefault<"a" | "b">("a", "b")
NoInfer<function (type parameter) A in <K, A>(predicate: (a: NoInfer<A>, k: K) => boolean): (self: HashMap<K, A>) => booleanA>, k: Kk: function (type parameter) K in <K, A>(predicate: (a: NoInfer<A>, k: K) => boolean): (self: HashMap<K, A>) => booleanK) => boolean): (self: HashMap<K, A>(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, A>(predicate: (a: NoInfer<A>, k: K) => boolean): (self: HashMap<K, A>) => booleanK, function (type parameter) A in <K, A>(predicate: (a: NoInfer<A>, k: K) => boolean): (self: HashMap<K, A>) => booleanA>) => boolean
<function (type parameter) K in <K, A>(self: HashMap<K, A>, predicate: (a: A, k: K) => boolean): booleanK, function (type parameter) A in <K, A>(self: HashMap<K, A>, predicate: (a: A, k: K) => boolean): booleanA>(self: HashMap<K, A>(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, A>(self: HashMap<K, A>, predicate: (a: A, k: K) => boolean): booleanK, function (type parameter) A in <K, A>(self: HashMap<K, A>, predicate: (a: A, k: K) => boolean): booleanA>, predicate: (a: A, k: K) => booleanpredicate: (a: Aa: function (type parameter) A in <K, A>(self: HashMap<K, A>, predicate: (a: A, k: K) => boolean): booleanA, k: Kk: function (type parameter) K in <K, A>(self: HashMap<K, A>, predicate: (a: A, k: K) => boolean): booleanK) => boolean): boolean
} = import internalinternal.const every: (<K, A>(
predicate: (a: NoInfer<A>, k: K) => boolean
) => (self: internal.HashMap<K, A>) => boolean) &
(<K, A>(
self: internal.HashMap<K, A>,
predicate: (a: A, k: K) => boolean
) => boolean)
every