Skip to content

Instantly share code, notes, and snippets.

@kings13y
Created May 28, 2012 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kings13y/2818299 to your computer and use it in GitHub Desktop.
Save kings13y/2818299 to your computer and use it in GitHub Desktop.
Minimal FizzBuzz implementation in Scala
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
}
}
@Deeds67
Copy link

Deeds67 commented Feb 2, 2017

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) :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment