(u: unknown): u is EqualChecks whether a value implements the Equal interface.
When to use
Use when you need generic utility code to distinguish Equal implementors
from plain values before calling [Equal.symbol] directly.
Details
- Pure function, no side effects.
- Returns
trueif and only ifuhas a property keyed by symbol. - Acts as a TypeScript type guard, narrowing the input to Equal.
Example (Checking Equal values)
import { Equal, Hash } from "effect"
class Token implements Equal.Equal {
constructor(readonly value: string) {}
[Equal.symbol](that: Equal.Equal): boolean {
return that instanceof Token && this.value === that.value
}
[Hash.symbol](): number {
return Hash.string(this.value)
}
}
console.log(Equal.isEqual(new Token("abc"))) // true
console.log(Equal.isEqual({ x: 1 })) // false
console.log(Equal.isEqual(42)) // falseexport const const isEqual: (u: unknown) => u is EqualChecks whether a value implements the
Equal
interface.
When to use
Use when you need generic utility code to distinguish Equal implementors
from plain values before calling [Equal.symbol] directly.
Details
- Pure function, no side effects.
- Returns
true if and only if u has a property keyed by
symbol
.
- Acts as a TypeScript type guard, narrowing the input to
Equal
.
Example (Checking Equal values)
import { Equal, Hash } from "effect"
class Token implements Equal.Equal {
constructor(readonly value: string) {}
[Equal.symbol](that: Equal.Equal): boolean {
return that instanceof Token && this.value === that.value
}
[Hash.symbol](): number {
return Hash.string(this.value)
}
}
console.log(Equal.isEqual(new Token("abc"))) // true
console.log(Equal.isEqual({ x: 1 })) // false
console.log(Equal.isEqual(42)) // false
isEqual = (u: unknownu: unknown): u: unknownu is Equal => hasProperty<"~effect/interfaces/Equal">(self: unknown, property: "~effect/interfaces/Equal"): self is { [K in "~effect/interfaces/Equal"]: 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/Equal"Defines the unique string identifier for the Equal interface.
When to use
Use when you implement custom equality and need the computed property key for
the equality method.
Details
This is a pure constant with no allocation or side effects.
Example (Implementing Equal on a class)
import { Equal, Hash } from "effect"
class UserId implements Equal.Equal {
constructor(readonly id: string) {}
[Equal.symbol](that: Equal.Equal): boolean {
return that instanceof UserId && this.id === that.id
}
[Hash.symbol](): number {
return Hash.string(this.id)
}
}
symbol)