Last active
August 29, 2015 14:24
-
-
Save oisdk/e81e73cf2da4eb93275b 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
extension GeneratorType { | |
mutating func any(predicate: Element -> Bool) -> Bool { | |
return next().map { el in predicate(el) || any(predicate) } ?? false | |
} | |
mutating func all(predicate: Element -> Bool) -> Bool { | |
return next().map { el in predicate(el) && all(predicate) } ?? true | |
} | |
} | |
var i = 0 | |
var g = anyGenerator { ++i } | |
func testIsOverFive(n: Int) -> Bool { | |
print(n) // 1, 2, 3, 4, 5, 6 | |
return n > 5 | |
} | |
let ans = g.any(testIsOverFive) // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment