Skip to content

Instantly share code, notes, and snippets.

@gavinking
Last active December 21, 2015 01:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gavinking/6226478 to your computer and use it in GitHub Desktop.
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.
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