Equatable
public protocol EquatableProtocol 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) // trueMethods
func isEqual(to: Self) -> Bool
func isEqual(to: Self) -> BoolReturns 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 = Booltype Output = Bool
type Output = BoolMethods
public func equal(to: Self) -> Bool
public func equal(to: Self) -> BoolBridges Equal.equal(to:) to Equatable.isEqual(to:).
ImplementsNotEqual
Associated Types
type Output
type OutputMethods
public func notEqual(to: Self) -> Bool
public func notEqual(to: Self) -> BoolDefault !=: delegates to == so there's a single source of truth.
Defined in lang/std/core/protocols.ks