Created
January 25, 2018 06:55
-
-
Save fpg1503/a9ae47528037b296391d8b9b9ef4e419 to your computer and use it in GitHub Desktop.
(a == 1 && a == 2 && a ==3).swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: 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