Reputation: 35
I have this:
getMask (/= 3) [1, 2, 3, 4, 5]
and result must be this:
[True, True, False, True, True]
i tried something like this
getMask p xs = [x | (x,m) <- enumerate xs, if p x then True else False]
but i get only numbers. I need list of booleans
Upvotes: 1
Views: 71
Reputation: 116139
You can use map :: (a -> b) -> [a] -> [b]
:
> map (/= 3) [1, 2, 3, 4, 5]
[True,True,False,True,True]
or a simple list comprehension:
getMask p xs = [p x | x <- xs]
Upvotes: 6