Created
November 25, 2012 16:15
-
-
Save ramn/4144203 to your computer and use it in GitHub Desktop.
FizzBuzz in scala, somewhat functional
This file contains hidden or 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 { | |
def main(args: Array[String]) = { | |
def m3(x: Int) = x % 3 == 0 | |
def m5(x: Int) = x % 5 == 0 | |
val checks = List((m3 _, "Fizz"), (m5 _, "Buzz")) | |
Stream.from(1) map { n => | |
checks filter (_._1(n)) map (_._2) reduceOption (_ + _) getOrElse n | |
} take 100 foreach println | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment