[EMAIL PROTECTED] wrote:
+=head1 Cross operators
+
+The final metaoperator is the C<X> metaoperator. It applies the
+modified operator across all permutations of its list arguments. All
+C<X> operators are of list infix precedence, and are list associative.
+
+The bare form of C<X> is considered an operator in its own right.
+Saying:
+
+ <a b> X 1,2 X <x y>
+
+produces
+
+ ['a', 1, 'x'],
+ ['a', 1, 'y'],
+ ['a', 2, 'x'],
+ ['a', 2, 'y'],
+ ['b', 1, 'x'],
+ ['b', 1, 'y'],
+ ['b', 2, 'x'],
+ ['b', 2, 'y']
Would it be possible to extend C<next> to pass its arguments to the
iterator being 'nexted'. Along with proper arguments to whichever lazy
object it generated by X, it'd enable this:
(where :$slice argument would cause X to increment the member of the
tuple at the appropriate index, and resets all the other ones):
for 1,2,3 X 1,2,3 -> [$i, $j] {
if $j > $i { next(slice => 0); }
say $i, $j;
}
11
21
22
31
32
33
As another example, if a tree iterator has :right keyword argument to
return the node to the right, you could do:
for $tree.each -> $node {
if $node.value > $goal { next; }
if $node.value < $goal {next :right; }
return $node;
}
Alternative proposal could be to allow expression after next, which gets
evaluated instead of incrementing the iterator, iterator is topic in
that expression and is replaced by the result.
So next True; causes infinite loop, next .left calls .left accessor and
next .right calls right accessor before reentering loop (but doesn't do
the default increment that for does).