sub mngrepper($n, $m=$n) {
sub (@xs, &f) {
(^$n X ^$m).grep(-> ($y, $x) { f(@xs[$x;$y]) })
}
}
my @puzzle = [<a b>], [<c d>];
my @visited = (True, False), ((Any), False);
for mngrepper(2)(@visited, ?*) -> ($y, $x) {
@puzzle[$x;$y] ~= '*'
}
say @puzzle;
# or save your n×m grepper for easy re-use
my &mngrep = mngrepper(4, 2);
my @xs = [<a b c d>], [<e f g h*>];
my @indices = mngrep(@xs, *.contains: '*');
for @indices -> ($y, $x) {
@xs[$x;$y] .= chop
}
say @xs;
Just use Deepgrep
for @xs.&deepgrep(*.contains('*'), :k) -> ($x, $y) {
@xs[$x;$y] .= chop
}