Equatable

public protocol Equatable

Protocol for types whose values can be compared for equality.

Equatable is the semantic counterpart to the raw Equal[Self] operator protocol: conformers implement isEqual returning Bool, and a blanket extension below derives both == and !=. Most types should reach for Equatable rather than Equal directly — the Bool associated-type binding is wired up automatically.

Examples

public struct Point: Equatable { public var x: Int64 public var y: Int64 public func isEqual(to other: Point) -> Bool { self.x == other.x and self.y == other.y } } Point(x: 1, y: 2) == Point(x: 1, y: 2) // true

Methods

func isEqual(to: Self) -> Bool

Returns true iff self and other are considered equal. Should be reflexive, symmetric, and transitive — Hashable requires equal values to hash equal, so don't drift from those laws.

ImplementsEqual

Associated Types

type Output = Bool
type Output = Bool

Methods

public func equal(to: Self) -> Bool

Bridges Equal.equal(to:) to Equatable.isEqual(to:).

ImplementsNotEqual

Associated Types

type Output

Methods

public func notEqual(to: Self) -> Bool

Default !=: delegates to == so there's a single source of truth.

Defined in lang/std/core/protocols.ks