employees.filter(predicate1).filter(predicate2).filter(predicate3)
instead of Iterables.filter(Iterables.filter(Iterables.filter(employees,predicate1), predicate2), predicate3) employees.filter(predicate1).filter(predicate2).filter(predicate3)
instead of Iterables.filter(Iterables.filter(Iterables.filter(employees,predicate1), predicate2), predicate3) filter predicate1 . filter predicate2 . filter predicate3 $ employees
Where . is function composition. filter (\x -> p1 x && p2 x && p3 x) employees
which can then be made points-free. {-# RULES
"filter/filter" forall f g xs. filter f (filter g xs) = filter (f.g) xs
#-}
It's a programmable programming language. forall f g xs. map f (map g xs) = map (f.g) xs
?As for filter, I presume something like
forall f g xs. filter f (filter g xs) = filter (\x. g x && f x) xs
would work. forall f g xs . filter f (filter g xs) = filter (\x -> g x && f x) xs
was exactly what I meant, thanks for the catch!employees.filter(predicate1, predicate2, predicate3);
@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);