Skip to content

Instantly share code, notes, and snippets.

@gfldex
gfldex / test2.p6
Created January 31, 2017 08:47 — forked from samcv/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;
});
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
# 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