3 ms·
Perl 6 would do that like this: @employees.grep($predicate1 & $predicate2 & $predicate3); The predicates can be a function, a regex, a type, or anything that
by ekiru 16y ago
Perl 6 would do that like this:
@employees.grep($predicate1 & $predicate2 & $predicate3);
The predicates can be a function, a regex, a type, or anything that can be smart-matched against.
Alternately, if you want to get the employees that match any of the predicates, you'd do the following:
@employees.grep($predicate1 | $predicate2 | $predicate3);
Or, if you want the employees that match only one of the predicates (think of xor):
@employees.grep($predicate1 ^ $predicate2 ^ $predicate3);
These can also be written, respectively, as:
@employees.grep(all($predicate1, $predicate2, $predicate3));
@employees.grep(any($predicate1, $predicate2, $predicate3));
@employees.grep(one($predicate1, $predicate2, $predicate3));
And, if you want things that match none of the predicates:
@employees.grep(none($predicate1, $predicate2, $predicate3));
You can combine these junction constructors. For example:
@employees.grep(all($predicate1, $predicate2) ^ $predicate3);