Last active
December 21, 2015 01:19
-
-
Save gavinking/6226478 to your computer and use it in GitHub Desktop.
See how I use a comprehension to pass a lazily evaluated stream of fizzbuzzes to printAll()? Note that a more efficient implementation of printAll() could eaily avoid the string concatenation, thus taking much better advantage of the laziness.
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
shared void run() => printAll { for (i in 0..50) fizzbuzz(i) }; | |
String fizzbuzz(Integer i) | |
=> (i%15==0 then "fizzbuzz") | |
else (i%3==0 then "fizz") | |
else (i%5==0 then "buzz") | |
else i.string; | |
void printAll({String*} strings) => print(", ".join(strings)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment