I would prefer to see this implemented as a global function. That way, autocomplete does not get polluted, but developers that want and know about this optimization still have easy access.
func areKnownIdentical<T: KnownIdenticalComparable>(_ lhs: T, _ rhs: T) -> Bool
The main benefit is that this allows working with optionals, where there are overloads to areKnownIdentical
with T?
on either side. If both values are nil
, return true
. If only one is nil
, return false
. If both are non-nil
, call protocol function (e.g. a.isKnownIdentical(to: b)
or static areKnownIdentical
on T
).