Hoogle Search
Within LTS Haskell 24.25 (ghc-9.10.3)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
mapMaybe :: (a -> Maybe b) -> [a] -> [b]classy-prelude ClassyPrelude 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 GHC.Internal.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]
mapM_ :: Monad m => (input -> m ()) -> UnfoldlM m input -> m ()deferred-folds DeferredFolds.UnfoldlM A more efficient implementation of mapM_
mapMap :: (a -> v) -> LabelMap a -> LabelMap vghc-lib-parser GHC.Cmm.Dataflow.Label No documentation available.
mapMapWithKey :: (Label -> a -> v) -> LabelMap a -> LabelMap vghc-lib-parser GHC.Cmm.Dataflow.Label No documentation available.
mapMember :: Label -> LabelMap a -> Boolghc-lib-parser GHC.Cmm.Dataflow.Label No documentation available.
mapMaybeDTyConEnv :: (a -> Maybe b) -> DTyConEnv a -> DTyConEnv bghc-lib-parser GHC.Core.TyCon.Env No documentation available.
mapMaybeBag :: (a -> Maybe b) -> Bag a -> Bag bghc-lib-parser GHC.Data.Bag No documentation available.
mapMaybeBagM :: Monad m => (a -> m (Maybe b)) -> Bag a -> m (Bag b)ghc-lib-parser GHC.Data.Bag No documentation available.
mapMaybeFsEnv :: (elt1 -> Maybe elt2) -> FastStringEnv elt1 -> FastStringEnv elt2ghc-lib-parser GHC.Data.FastString.Env No documentation available.
mapMaybe :: (a -> Maybe b) -> Word64Map a -> Word64Map bghc-lib-parser GHC.Data.Word64Map.Internal 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"