Skip to content

Instantly share code, notes, and snippets.

View test2.p6
my %results;
for ^10 {
%results{$_}<bytes> = (1..10).pick;
}
say %results.perl;
say %results.keys.sort({
my $c = %results{$^a}<bytes> cmp %results{$^b}<bytes>;
$c ?? $c !! $^a.Int cmp $^b.Int;
});
View accepts.pl6
class Command {
has Str $.name;
method ACCEPTS(Any:D $other) {
return $other ~~ Str and $other ~~ $!name;
}
}
my $c = Command.new(name => 'foo');
say ('foo' ~~ $c); #outputs: True
View gist:ecde10b59aab332941a245dc4e74ddf0
# function to be wrapped:
sub square-root($x) { $x.sqrt }
&square-root.wrap(sub ($num) {
nextsame if $num >= 0;
1i * callwith(abs($num));
});
say square-root(4); # 2
say square-root(-4); # 0+2i