According to the documentation, sort
compares using infix:<cmp>
.
But:
class Point
{
has Int $.x;
has Int $.y;
method Str { "($!x,$!y)" }
method gist { self.Str }
}
multi sub infix:<cmp>(Point $a, Point $b) { $a.y cmp $b.y || $a.x cmp $b.x }
my @p = Point.new(:3x, :2y), Point.new(:2x, :4y), Point.new(:1x, :1y);
say @p.sort;
gives output:
((1,1) (2,4) (3,2))
When I use:
say @p.sort(&infix:<cmp>);
it does give the proper output:
((1,1) (3,2) (2,4))
Is this a bug, a feature, or a flaw in the documentation?
And is there a way to make .sort()
on a list of a Point
s use a custom sort order without specifying a routine?