base -Data.Maybe  

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]
catMaybes :: Monad m => Conduit (Maybe a) m a

conduit -Data.Conduit.List  

Filter the Just values from a stream, discarding the Nothing values.

Subject to fusion

Since 0.5.1

haskell98 -Maybe  

The catMaybes function takes a list of Maybes and returns a list of all the Just values.

HaXml -Text.XML.HaXml.XmlContent.Parser  

The catMaybes function takes a list of Maybes and returns a list of all the Just values.

catMaybes :: (IsSequence (f (Maybe t)), Functor f, Element (f (Maybe t)) ~ Maybe t) => f (Maybe t) -> f t

mono-traversable -Data.Sequences  

Takes all of the Just values from a sequence of Maybe ts and concatenates them into an unboxed sequence of ts.

Since 0.6.2

catMaybes :: C time => T time (Maybe body) -> T time body

event-list -Data.EventList.Relative.TimeBody  

Adds times in a left-associative fashion. Use this if the time is a strict data type.

catMaybes :: C time => T time (Maybe body) -> T time body

event-list -Data.EventList.Relative.TimeTime  

Adds times in a left-associative fashion. Use this if the time is a strict data type.

basic-prelude -CorePrelude  

The catMaybes function takes a list of Maybes and returns a list of all the Just values.

fay-base -Data.Maybe  

The catMaybes function takes a list of Maybes and returns a list of all the Just values.

haskell2010 -Data.Maybe  

The catMaybes function takes a list of Maybes and returns a list of all the Just values.

base -Data.Maybe  

The mapMaybe function is a version of map which can throw out elements. In particular, the functional argument returns something of type Maybe b. If this is Nothing, no element is added on to the result list. If it is Just b, then b is included in the result list.

Examples

Using mapMaybe f x is a shortcut for catMaybes $ map f x in most cases:

>>> import Text.Read ( readMaybe )
>>> let readMaybeInt = readMaybe :: String -> Maybe Int
>>> mapMaybe readMaybeInt ["1", "Foo", "3"]
[1,3]
>>> catMaybes $ map readMaybeInt ["1", "Foo", "3"]
[1,3]

If we map the Just constructor, the entire list should be returned:

>>> mapMaybe Just [1,2,3]
[1,2,3]
catMaybesR :: C time => T time (Maybe body) -> T time body

event-list -Data.EventList.Relative.TimeTime  

Adds times in a right-associative fashion. Use this if the time is a data type like lazy Peano numbers or Numeric.NonNegative.Chunky.

catMaybes :: DSignal era (Maybe val) -> DSignal era val

grapefruit-frp -FRP.Grapefruit.Signal.Discrete  

Converts all occurences with values of the form Just val into occurences with value val and drops all occurences with value Nothing.