Hoogle Search
Within LTS Haskell 24.4 (ghc-9.10.2)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
-
pipes Pipes.Prelude Apply a function to all values flowing downstream, and forward each element of the result.
mapM :: Monad m => (a -> m b) -> Pipe a b m rpipes Pipes.Prelude Apply a monadic function to all values flowing downstream
mapM return = cat mapM (f >=> g) = mapM f >-> mapM g
mapM_ :: Monad m => (a -> m ()) -> Consumer' a m rpipes Pipes.Prelude Consume all values using a monadic function
mapMaybe :: forall (m :: Type -> Type) a b r . Functor m => (a -> Maybe b) -> Pipe a b m rpipes Pipes.Prelude (mapMaybe f) yields Just results of f. Basic laws:
mapMaybe (f >=> g) = mapMaybe f >-> mapMaybe g mapMaybe (pure @Maybe . f) = mapMaybe (Just . f) = map f mapMaybe (const Nothing) = drain
As a result of the second law,mapMaybe return = mapMaybe Just = cat
mapLeft :: (a1 -> a2) -> Either a1 b -> Either a2 brio RIO.Prelude Apply a function to a Left constructor
mapM :: (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b)rio RIO.Prelude 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_.
Examples
mapM is literally a traverse with a type signature restricted to Monad. Its implementation may be more efficient due to additional power of Monad.mapM_ :: (Foldable t, Monad m) => (a -> m b) -> t a -> m ()rio RIO.Prelude 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. mapM_ is just like traverse_, but specialised to monadic actions.
mapMaybe :: (a -> Maybe b) -> [a] -> [b]rio RIO.Prelude 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]
mapMaybeA :: Applicative f => (a -> f (Maybe b)) -> [a] -> f [b]rio RIO.Prelude Applicative mapMaybe.
mapMaybeM :: Monad m => (a -> m (Maybe b)) -> [a] -> m [b]rio RIO.Prelude Monadic mapMaybe.