:: (a -> m (Maybe b)) -> [a] -> m [b] package:relude

The monadic version of the mapMaybe function.
>>> :{
evenInHalf :: Int -> IO (Maybe Int)
evenInHalf n
| even n = pure $ Just $ n `div` 2
| otherwise = pure Nothing
:}
>>> mapMaybeM evenInHalf [1..10]
[1,2,3,4,5]