Created
December 3, 2015 14:01
-
-
Save JanGorman/e12f3b442e57e0afe441 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| let numbers = AnySequence { () -> AnyGenerator<Int> in | |
| var i = 1 | |
| return anyGenerator { | |
| return i++ | |
| } | |
| }.lazy | |
| let fizzes = numbers.map{ $0 % 3 == 0 ? "Fizz" : "" } | |
| let buzzes = numbers.map{ $0 % 5 == 0 ? "Buzz" : "" } | |
| let pattern = zip(fizzes, buzzes).lazy.map { (fizz, buzz) in fizz + buzz } | |
| let fizzbuzz = zip(pattern, numbers).lazy.map { (p, n) in p.isEmpty ? String(n) : p } | |
| for fb in fizzbuzz.prefix(100) { | |
| print(fb) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment