Skip to content

Instantly share code, notes, and snippets.

@grigorye
Created July 28, 2020 18:12
Show Gist options
  • Save grigorye/22686aead9da2013d1a7d1a07ae03462 to your computer and use it in GitHub Desktop.
Save grigorye/22686aead9da2013d1a7d1a07ae03462 to your computer and use it in GitHub Desktop.
// 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