News for hackers. Stuff that matters.
Re:Ladies, look at your code. Now back to mine. by ekiru on Saturday August 28, 2010 @03:02PM (#1642202)
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);

There are no comments on this comment yet.