Skip to content

Instantly share code, notes, and snippets.

@JanGorman
Created December 3, 2015 14:01
Show Gist options
  • Select an option

  • Save JanGorman/e12f3b442e57e0afe441 to your computer and use it in GitHub Desktop.

Select an option

Save JanGorman/e12f3b442e57e0afe441 to your computer and use it in GitHub Desktop.
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