Note. This answer implements the specification expressed by words and an example in the question, and not the other specified in the implementation multifilter. For the latest opportunity, see gallais' .
Sibi's answer shows how you should do this. In any case, it is instructive to consider how you could write your function using filter. To begin with, we can establish two facts:
multifilter filter pred pred. " ", , , .multifilter f xs ys , , xs, " " - ys. , [3,2], [2,3] ( ) .
, :
multifilter :: (a -> a -> Bool) -> [a] -> [a] -> [a]
multifilter f xs ys = filter pred xs
where
pred = undefined -- TODO
, , pred. x, pred True, y of ys, f x y . , any:
pred x = any (\y -> f x y) ys
-- Or, with less line noise:
pred x = any (f x) ys
, multifilter ...
multifilter :: (a -> a -> Bool) -> [a] -> [a] -> [a]
multifilter f xs ys = filter pred xs
where
pred x = any (f x) ys
-- Or, more compactly:
multifilter :: (a -> a -> Bool) -> [a] -> [a] -> [a]
multifilter f xs ys = filter (\x -> any (f x) ys) xs
... intersectBy, , intersectBy.