class Point {
method distance {...}
method union {...}
}
my @points = [Point.new, Point.new, Point.new];
my $top = 3;
# One line: syntax is OK but too long
@points.combinations(2).sort(-> [$a, $b] { $a.distance($b) })[^$top].map(-> [$a, $b] { $a.union($b) });
# Trying to split methods per line:
# Unable to parse expression in bracketed infix; couldn't find final ']' (corresponding starter was at line 18)
# at /home/glot/main.raku:18
# ------> [32m.sort(-> [$a, $b] { $a.distance($b) })[^[33m⏏[31m$top][0m
@points
.combinations(2)
.sort(-> [$a, $b] { $a.distance($b) })[^$top]
.map(-> [$a, $b] { $a.union($b) }) });
}
# Doesn't work either
# Malformed postfix call (only basic method calls that exclusively use a dot can be detached)
# at /home/glot/main.raku:29
# ------> [32m .[33m⏏[31m[^$top][0m
@points
.combinations(2)
.sort(-> [$a, $b] { $a.distance($b) })
.[^$top]
.map(-> [$a, $b] { $a.union($b) }) });
# Using the feed operator, I need something to allow feeding into a block?
# Because I can't do `==> { .[^$top] }` directly (feed into a block?)
# Or either `==> *.[^$top]` (feed into a WhateverCode?)
# So I made this then() routine
sub then(&code, $_) { code($_) }
@points.combinations(2)
==> sort(-> [$a, $b] { $a.distance($b) })
==> then({ .[^$top] })
==> map(-> [$a, $b] { $a.union($b) });