Skip to content

Instantly share code, notes, and snippets.

@skht777
Last active January 8, 2017 07:33
Show Gist options
  • Save skht777/5664297a361bfd3b3cc36e12efd027c3 to your computer and use it in GitHub Desktop.
Save skht777/5664297a361bfd3b3cc36e12efd027c3 to your computer and use it in GitHub Desktop.
ScalaのStreamで書いたFizzBuzz
object FizzBuzzStream {
def apply(fizz: Int = 3, buzz: Int = 5): Stream[String] = {
def stream(i: Int): Stream[String] = {
val s = (i % fizz, i % buzz) match {
case (0, 0) => "FizzBuzz"
case (0, _) => "Fizz"
case (_, 0) => "Buzz"
case _ => i.toString
}
s #:: stream(i + 1)
}
stream(1)
}
}
object FizzBuzz extends App {
println(FizzBuzzStream() take 100 mkString " ")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment