Skip to content

Instantly share code, notes, and snippets.

@masak
Created September 4, 2015 10:39
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 masak/b84a87a694217c9508d6 to your computer and use it in GitHub Desktop.
Save masak/b84a87a694217c9508d6 to your computer and use it in GitHub Desktop.
FizzBuzz in very FP Perl 6 (inspired by lichtkind++'s talk)
constant nums = 1, 2, 3 ... Inf;
sub replace($divisor, $word) {
-> $n { $n %% $divisor ?? $word !! $n }
}
constant fizzbuzz = nums\
.map(replace(3, "Fizz"))\
.map(replace(5, "Buzz"))\
.map(replace(15, "FizzBuzz"));
say fizzbuzz[^100];
$ perl6 fizzbuzz
===SORRY!=== Error while compiling fizzbuzz
An exception occurred while evaluating a constant
at fizzbuzz:7
Exception details:
===SORRY!=== Error while compiling
Cannot invoke this object (REPR: Null, cs = 0)
at :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment