Input: [Just "foo", Just "bar", Nothing, Just "quux"]
Output: ["foo", "bar", "quux"]
I'm not satisfied with the following solution using fromJust
because it's not very portable to elm which doesn't like unsafe functions:
extract list = map fromJust $ filter isJust list
Is there another concise / idiomatic way to achieve this?
You can use catMaybes
:
import Data.Maybe
catMaybes list
Λ: :m + Data.Maybe
Λ: concatMap maybeToList [Just "foo", Just "bar", Nothing, Just "quux"]
["foo","bar","quux"]
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