Skip to content

Instantly share code, notes, and snippets.

@michaelgwelch
Created June 5, 2014 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelgwelch/16a6c520ca80d77dd4a4 to your computer and use it in GitHub Desktop.
Save michaelgwelch/16a6c520ca80d77dd4a4 to your computer and use it in GitHub Desktop.
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