Multiple dispatch of `in`

Base.:(==)(a::Dog, b::Dog) = a.breed == b.breed
Base.hash(a::Dog, h::UInt) = hash(a.breed, h)

where if you change the definition of equality you also need to change Base.hash so that hash tables (e.g. Set data structures) work. (By default, isequal calls ==.)

Alternatively, you define your own in-like function (e.g. the ∈ᵇ operator) to be whatever you want, while leaving equality as-is.

2 Likes