3 ms·
All that and his code examples are bizarre trash. Despite the way he tries to crap on Perl (5) by referring to a Perl 6 (now Raku) example, I find a Raku FizzB
by daotoad 7y ago
All that and his code examples are bizarre trash.
Despite the way he tries to crap on Perl (5) by referring to a Perl 6 (now Raku) example, I find a Raku FizzBuzz far easier to read than his mess:
multi sub fb( Int $n where * %% none(3,5) ) { return $n }
multi sub fb( Int $n where * %% all(3,5) ) { return 'fizzbuzz' }
multi sub fb( Int $n where * %% 3 ) { return 'fizz' }
multi sub fb( Int $n where * %% 5 ) { return 'buzz' }
.say for (1..15).map({ fb($_) } );
Or if you want to name your specialized types:
subset Fizzy of Int where * %% 3;
subset Buzzy of Int where * %% 5;
subset FizzBuzzy of Int where * %% (3&5);
subset Otherwyzy of Int where not * %% (3|5);
multi sub sfb( Otherwyzy $n ) { return $n }
multi sub sfb( FizzBuzzy $n ) { return 'fizzbuzz' }
multi sub sfb( Fizzy $n ) { return 'fizz' }
multi sub sfb( Buzzy $n ) { return 'buzz' }
.say for (1..15).map({ sfb($_) } );