mapM package:rio

Map each element of a structure to a monadic action, evaluate these actions from left to right, and collect the results. For a version that ignores the results see mapM_.
O(n) Apply the monadic action to all elements of the vector, yielding a vector of results
O(n) Apply the monadic action to all elements of the vector, yielding a vector of results
O(n) Apply the monadic action to all elements of the vector, yielding a vector of results
O(n) Apply the monadic action to all elements of the vector, yielding a vector of results
Transform this map by applying a function to every value and retaining only some of them.
Transform this map by applying a function to every value and retaining only some of them.
O(n). Map values and collect the Just results.
let f x = if x == "a" then Just "new a" else Nothing
mapMaybe f (fromList [(5,"a"), (3,"b")]) == singleton 5 "new a"
O(n). Map keys/values and collect the Just results.
let f k _ = if k < 5 then Just ("key : " ++ (show k)) else Nothing
mapMaybeWithKey f (fromList [(5,"a"), (3,"b")]) == singleton 3 "key : 3"
Map each element of a structure to a monadic action, evaluate these actions from left to right, and ignore the results. For a version that doesn't ignore the results see mapM. As of base 4.8.0.0, mapM_ is just traverse_, specialized to Monad.
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]
Applicative mapMaybe.
Monadic mapMaybe.
O(n). The mapMonotonic f s == map f s, but works only when f is strictly increasing. The precondition is not checked. Semi-formally, we have:
and [x < y ==> f x < f y | x <- ls, y <- ls]
==> mapMonotonic f s == map f s
where ls = toList s
O(n) Apply the monadic action to all elements of a vector and ignore the results
O(n) Drop elements when predicate returns Nothing
O(n) Apply the monadic action to all elements of a vector and ignore the results
O(n) Drop elements when predicate returns Nothing
O(n) Apply the monadic action to all elements of a vector and ignore the results
O(n) Drop elements when predicate returns Nothing
O(n) Apply the monadic action to all elements of a vector and ignore the results
O(n) Drop elements when predicate returns Nothing
A vesion of contramapMaybeGLogFunc which supports filering.
Extend foldMap to allow side effects. Internally, this is implemented using a strict left fold. This is used for performance reasons. It also necessitates that this function has a Monad constraint and not just an Applicative constraint. For more information, see https://github.com/commercialhaskell/rio/pull/99#issuecomment-394179757.
A generic monadic transformation that maps over the immediate subterms The default definition instantiates the type constructor c in the type of gfoldl to the monad datatype constructor, defining injection and projection using return and >>=.