Damian Conway <[EMAIL PROTECTED]> writes:
> David Wheeler wrote:
>
>> Isn't that just:
>> for @array_of_random_values_and_types, 'ok' -> $t {
>> when 'ok' { yada(); last }
>> last unless some_sort_of_test($t);
>> }
>> IOW, the topic is only 'ok' when all of the items in the array have
>> been processed
>
> Unless, of course, the string 'ok' is also one of the random_values_and_types.
> Hence my alternative solution.
Or:
my $guard = Object.new;
for @array_of_random_values_and_types, $guard
-> { when $guard { yada(); last }
last unless some_sort_of_test($_) }
If there's some danger of some weird equality thing somehow causing a
problem there, you might need to make a Guard class with a very strict
'=~' implementation, but otherwise I can't see any problem.
Of course, that's better if some_sort_of_test is actually a method,
because then it becomes:
my $guard = class { method some_sort_of_test { yada() }}.new;
for [EMAIL PROTECTED], $guard
-> { last unless .some_sort_of_test }
All of which means you can wrap it up in a macro and prove Simon's
point about what's syntax and what's CP6AN:
macro unless_all( Block &test is parsed /<perl.expression>/,
Block &consequence, [EMAIL PROTECTED] )
{ my $guard = Object.new;
for [EMAIL PROTECTED], $guard
-> { when $guard { &consequence() ; last }
when &test { last } } }
But I've probably got the signature slightly wrong.
Higher Order Functions/Methods/Macros are great aren't they?