I have a Perl 6 function currently written in the form:
sub func($x) {
for @data -> $datum {
if condition($datum, $x) ff * {
# Do various things
}
}
# Do various other things
}
I want the "various things" code to be run for the first element in
C<@data> for which C<condition($datum, $x)> returns true and for every
element in C<@data> after that (regardless of whether C<condition()>
is true, and ignoring the possibility of C<last>s) and for the state
of whether C<condition()> has returned true to be reset for each
invocation of C<func()>. I originally thought that the C<ff> operator
with Whatever as its right-hand operand (so that it never unflipped/
flopped) would do what I meant, but the documentation for Perl 5's
C<..> in scalar context (which S03 currently defers to) seems to imply
that C<ff>'s state is maintained across function invocations. Rakudo
doesn't seem to have implemented C<ff> yet, so I can't test it, but if
the state is indeed maintained across calls in Perl 6, how should I
write C<func()> instead? The best way I can think of is the very C-
like practice of creating a variable to store whether
C<condition($datum, $x)> has returned true yet and updating it each
iteration until true is returned, but it seems like Perl 6 should have
a better way.
Thanking you in advance,
Minimiscience