Skip to content

Instantly share code, notes, and snippets.

@joebalancio
Last active August 29, 2015 14:01
Show Gist options
  • Save joebalancio/1b9ec06dd2f6a532b4af to your computer and use it in GitHub Desktop.
Save joebalancio/1b9ec06dd2f6a532b4af to your computer and use it in GitHub Desktop.
Fizz Buzz in Scala
val rules = Map(3 -> "fizz", 5 -> "buzz")
for {
i <- 1 to 100
val out = rules.map { case (m, w) => if (i % m == 0) Option(w) else None }.flatten.reduceOption(_ + _).getOrElse(i)
} println(out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment