Created
May 28, 2012 10:06
-
-
Save kings13y/2818299 to your computer and use it in GitHub Desktop.
Minimal FizzBuzz implementation in Scala
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
package org.scalabound.scatdd | |
object FizzBuzz { | |
def eval(x: Int) = (x % 3, x % 5, x) match { | |
case(0, 0, _) => "FizzBuzz" | |
case(0, _, _) => "Fizz" | |
case(_, 0, _) => "Buzz" | |
case _ => "" + x | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You don't need x in the tuple as well, you have access to it from the function's parameter. Would work with just a tuple of (x % 3, x % 5) :)