Skip to content

Instantly share code, notes, and snippets.

@slpsys
Last active December 12, 2017 21:54
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 slpsys/5461900 to your computer and use it in GitHub Desktop.
Save slpsys/5461900 to your computer and use it in GitHub Desktop.
Because always moar.
object fizzBuzzStream extends App {
type FizzBuffer = (Int, String)
def fb(b: FizzBuffer)(i:Int, s:String) = if (b._1 % i == 0) { new FizzBuffer(b._1, b._2 + s) } else { b }
def fizz = fb(_:FizzBuffer)(3, "Fizz")
def buzz = fb(_:FizzBuffer)(5, "Buzz")
def fizzBuzz = fizz andThen buzz
val naturals: Stream[Int] = 1 #:: naturals.map {n => n + 1}
val fizzyStream = naturals.map(n => fizzBuzz(new FizzBuffer(n, "")))
print(fizzyStream.take(100).toList)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment