Hyperlinkv0.8.0-beta.28

Hash

Hash.structureconsteffect/Hash.ts:470
<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
hashing
Source effect/Hash.ts:4701 lines
export const structure = <A extends object>(o: A) => structureKeys(o, getAllObjectKeys(o))
Referenced by 1 symbols