Created
July 28, 2020 18:12
-
-
Save grigorye/22686aead9da2013d1a7d1a07ae03462 to your computer and use it in GitHub Desktop.
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
// Reusing the idea in https://gist.github.com/akosma/07249e6718ace1ba6066 | |
precedencegroup ElementOfPrecedence { | |
associativity: left | |
higherThan: BitwiseShiftPrecedence | |
} | |
infix operator ∈ : ElementOfPrecedence | |
func ∈<T> (x: T, array: [T]) -> Bool where T: Equatable { | |
array.contains(x) | |
} | |
infix operator ∉ : ElementOfPrecedence | |
func ∉<T> (x: T, array: [T]) -> Bool where T: Equatable { | |
!(x ∈ array) | |
} | |
/// | |
assert("alpha" ∈ ["alpha", "beta", "gamma"]) | |
assert("alpha" ∉ ["omega", "gamma", "delta"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment