Expressively comparing a value with a list of candidates
Continuing to experiment with expressive ways of comparing a value with a list of candidates in Swift. Adding an extension on Equatable
is probably my favorite approach so far.
extension Equatable {
func isAny(of candidates: Self...) -> Bool {
return candidates.contains(self)
}
}
let isHorizontal = direction.isAny(of: .left, .right)