Created
October 29, 2014 10:36
-
-
Save davepkennedy/b9d45ddbd6c5c669c23f to your computer and use it in GitHub Desktop.
Functional FizzBuzz
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
| def from (i: Int): Stream[Int] = i #:: from(i+1) | |
| val nats = from(0) | |
| val fb = nats map { | |
| n => | |
| if (n % 15 == 0) "fizzbuzz" | |
| else if (n % 3 == 0) "fizz" | |
| else if (n % 5 == 0) "buzz" | |
| else n.toString | |
| } | |
| fb.take(20) foreach println |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment