Last active
December 12, 2017 21:54
-
-
Save slpsys/5461900 to your computer and use it in GitHub Desktop.
Because always moar.
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
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