Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Swift Programming Language (Apple) Predicate<T>
let iseven = Predicate { (n:Int) -> Bool in n % 2 == 0 }
iseven[7]
iseven[6]
class Predicate<T> {
let pred:(T) -> Bool
init(pred:(T) -> Bool) {
self.pred = pred
}
subscript(input:T) -> Bool {
get {
return pred(input)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.