Skip to content

Instantly share code, notes, and snippets.

@fpg1503
Created January 25, 2018 06:55
Show Gist options
  • Save fpg1503/a9ae47528037b296391d8b9b9ef4e419 to your computer and use it in GitHub Desktop.
Save fpg1503/a9ae47528037b296391d8b9b9ef4e419 to your computer and use it in GitHub Desktop.
(a == 1 && a == 2 && a ==3).swift
//: Playground - noun: a place where people can play
struct EqualsMultiple<T: Equatable> {
let values: [T]
}
extension EqualsMultiple: ExpressibleByArrayLiteral {
typealias ArrayLiteralElement = T
init(arrayLiteral elements: T...) {
values = elements
}
}
func ==<T>(lhs: EqualsMultiple<T>, rhs: T) -> Bool {
return lhs.values.contains(rhs)
}
func ==<T>(lhs: T, rhs: EqualsMultiple<T>) -> Bool {
return rhs == lhs
}
let a: EqualsMultiple = [1,2,3]
if a == 1 && a == 2 && a == 3 {
print("Success!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment