Created
November 22, 2014 22:23
-
-
Save michalrus/05efe311f815f96e6a4a to your computer and use it in GitHub Desktop.
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 Main extends App { | |
def fizzBuzz(num: Int, mapping: Map[Int, String]): List[Either[Int, String]] = | |
(1 to num).toList map { i ⇒ | |
mapping.toList.sorted flatMap { | |
case (k, v) if i % k == 0 ⇒ List(v) | |
case _ ⇒ Nil | |
} match { | |
case Nil ⇒ Left(i) | |
case rs ⇒ Right(rs.mkString) | |
} | |
} | |
fizzBuzz(16, Map(3 → "Fizz", 5 → "Buzz")) foreach println | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment