I have two functions that I would like to combine to use with filter
to filter a list of Item
s.
Here's a minimal example of what I'm trying to achieve:
data Item = Item { itemName :: String, itemSize :: Int }
hasName :: String -> Item -> Bool
hasName name i
| itemName i == name = True
| otherwise = False
hasSize :: Int -> Item -> Bool
hasSize size i
| itemSize i == size = True
| otherwise = False
The only solution I know to filter items that have "This" name
and size
42 is to call filter twice:
items = [Item "This" 2, Item "That" 42, Item "This" 42, Item "No" 9]
filter (hasName "This") $ filter (hasSize 42) items
However, I was wondering if there's some way to "combine" those two together and call filter
just once.