(u: unknown): u is HashChecks whether a value implements the Hash interface.
When to use
Use to detect whether an unknown value provides a custom hash implementation.
Details
This function determines whether a given value has the Hash symbol property, indicating that it can provide its own hash value implementation.
Example (Checking for Hash support)
import { Hash } from "effect"
class MyHashable implements Hash.Hash {
[Hash.symbol]() {
return 42
}
}
const obj = new MyHashable()
console.log(Hash.isHash(obj)) // true
console.log(Hash.isHash({})) // false
console.log(Hash.isHash("string")) // falseexport const const isHash: (u: unknown) => u is HashChecks whether a value implements the Hash interface.
When to use
Use to detect whether an unknown value provides a custom hash implementation.
Details
This function determines whether a given value has the Hash symbol property,
indicating that it can provide its own hash value implementation.
Example (Checking for Hash support)
import { Hash } from "effect"
class MyHashable implements Hash.Hash {
[Hash.symbol]() {
return 42
}
}
const obj = new MyHashable()
console.log(Hash.isHash(obj)) // true
console.log(Hash.isHash({})) // false
console.log(Hash.isHash("string")) // false
isHash = (u: unknownu: unknown): u: unknownu is Hash => hasProperty<"~effect/interfaces/Hash">(self: unknown, property: "~effect/interfaces/Hash"): self is { [K in "~effect/interfaces/Hash"]: unknown; } (+1 overload)Checks whether a value has a given property key.
When to use
Use when you need a Predicate guard for property access on unknown
values with a simple structural object check.
Details
Uses the in operator and isObjectKeyword. This does not check property
value types.
Example (Guarding object properties)
import { Predicate } from "effect"
const hasName = Predicate.hasProperty("name")
const data: unknown = { name: "Ada" }
if (hasName(data)) {
console.log(data.name)
}
hasProperty(u: unknownu, const symbol: "~effect/interfaces/Hash"Defines the unique identifier used to identify objects that implement the Hash interface.
When to use
Use as the computed property key for the method that supplies a custom hash
value on a Hash implementor.
symbol)