Last active
January 8, 2017 07:33
-
-
Save skht777/5664297a361bfd3b3cc36e12efd027c3 to your computer and use it in GitHub Desktop.
ScalaのStreamで書いたFizzBuzz
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 { | |
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