I have a list comprehension in Haskell that specifies a predicate on a Maybe type:
[x | x <- listOfMaybes, isJust(f y), x == fromJust(f y)]
is there a way to simplify this expression?
If you simply want to filter out all the Nothing
s, shang's answer gives the most concise solution. However, it can be done easily in a list comprehension:
[x | Just x <- f y]
You can simply use catMaybes
(from Data.Maybe
) to filter out all Nothing
values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With