Skip to content

Instantly share code, notes, and snippets.

@oisdk
Created July 3, 2015 17:30
Show Gist options
  • Save oisdk/5b367748dec9844576ee to your computer and use it in GitHub Desktop.
Save oisdk/5b367748dec9844576ee to your computer and use it in GitHub Desktop.
private extension GeneratorType {
mutating func any(@noescape pred: Element -> Bool) -> Bool {
return next().map { el in pred(el) || any(pred) } ?? false
}
mutating func all(@noescape pred: Element -> Bool) -> Bool {
return next().map { el in pred(el) && all(pred) } ?? true
}
}
public extension SequenceType {
func any(@noescape predicate: Generator.Element -> Bool) -> Bool {
var g = self.generate()
return g.any(predicate)
}
func all(@noescape predicate: Generator.Element -> Bool) -> Bool {
var g = self.generate()
return g.all(predicate)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment