<A extends object>(o: A): numberComputes a structural hash for an object using Effect's object key collection.
When to use
Use to hash an object from all structural keys collected by Effect.
Details
The hash is based on the object's structural keys and their values, including symbol keys and relevant prototype keys for non-plain objects.
Example (Hashing object structures)
import { Hash } from "effect"
const obj1 = { name: "John", age: 30 }
const obj2 = { name: "Jane", age: 25 }
const obj3 = { name: "John", age: 30 }
console.log(Hash.structure(obj1)) // hash of obj1
console.log(Hash.structure(obj2)) // different hash
console.log(Hash.structure(obj3)) // same as obj1
// Objects with same properties produce same hash
console.log(Hash.structure(obj1) === Hash.structure(obj3)) // trueexport const const structure: <A extends object>(
o: A
) => number
Computes a structural hash for an object using Effect's object key collection.
When to use
Use to hash an object from all structural keys collected by Effect.
Details
The hash is based on the object's structural keys and their values, including
symbol keys and relevant prototype keys for non-plain objects.
Example (Hashing object structures)
import { Hash } from "effect"
const obj1 = { name: "John", age: 30 }
const obj2 = { name: "Jane", age: 25 }
const obj3 = { name: "John", age: 30 }
console.log(Hash.structure(obj1)) // hash of obj1
console.log(Hash.structure(obj2)) // different hash
console.log(Hash.structure(obj3)) // same as obj1
// Objects with same properties produce same hash
console.log(Hash.structure(obj1) === Hash.structure(obj3)) // true
structure = <function (type parameter) A in <A extends object>(o: A): numberA extends object>(o: A extends objecto: function (type parameter) A in <A extends object>(o: A): numberA) => const structureKeys: (
o: object,
keys: Iterable<PropertyKey>
) => number
Computes a hash value for an object using only the specified keys.
When to use
Use to hash an object by a selected set of property keys.
Details
This function allows you to hash an object by considering only specific keys,
which is useful when you want to create a hash based on a subset of an object's
properties.
Example (Hashing selected object keys)
import { Hash } from "effect"
const person = { name: "John", age: 30, city: "New York" }
// Hash only specific keys
const hash1 = Hash.structureKeys(person, ["name", "age"])
const hash2 = Hash.structureKeys(person, ["name", "city"])
console.log(hash1) // hash based on name and age
console.log(hash2) // hash based on name and city
// Same keys produce the same hash
const person2 = { name: "John", age: 30, city: "Boston" }
const hash3 = Hash.structureKeys(person2, ["name", "age"])
console.log(hash1 === hash3) // true
structureKeys(o: A extends objecto, function getAllObjectKeys(obj: object): Set<PropertyKey>getAllObjectKeys(o: A extends objecto))