The
catMaybes function takes a list of
Maybes and
returns a list of all the
Just values.
Examples
Basic usage:
>>> catMaybes [Just 1, Nothing, Just 3]
[1,3]
When constructing a list of
Maybe values,
catMaybes can
be used to return all of the "success" results (if the list is the
result of a
map, then
mapMaybe would be more
appropriate):
>>> import Text.Read ( readMaybe )
>>> [readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ]
[Just 1,Nothing,Just 3]
>>> catMaybes $ [readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ]
[1,3]