-
-
Save masak/b84a87a694217c9508d6 to your computer and use it in GitHub Desktop.
FizzBuzz in very FP Perl 6 (inspired by lichtkind++'s talk)
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
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]; |
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
$ 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