Maybes

ghc-8.10.7: The GHC API

Safe Haskell | None
Language | Haskell2010

Maybes

Contents

- MaybeT

Synopsis

- module Data.Maybe
- data MaybeErr err val
  - = Succeeded val
  - | Failed err
- failME :: err -> MaybeErr err val
- isSuccess :: MaybeErr err val -> Bool
- orElse :: Maybe a -> a -> a
- firstJust :: Maybe a -> Maybe a -> Maybe a
- firstJusts :: [Maybe a] -> Maybe a
- whenIsJust :: Monad m => Maybe a -> (a -> m ()) -> m ()
- expectJust :: HasCallStack => String -> Maybe a -> a
- rightToMaybe :: Either a b -> Maybe b
- newtype MaybeT (m :: Type -> Type) a = MaybeT {
  - runMaybeT :: m (Maybe a)
  }
- liftMaybeT :: Monad m => m a -> MaybeT m a
- tryMaybeT :: IO a -> MaybeT IO a

# Documentation

module Data.Maybe

data MaybeErr err val #

Constructors

Succeeded val |
Failed err |

#### Instances

Instances details

Monad (MaybeErr err) # |
Instance details Defined in Maybes Methods (>>=) :: MaybeErr err a -> (a -> MaybeErr err b) -> MaybeErr err b Source # (>>) :: MaybeErr err a -> MaybeErr err b -> MaybeErr err b Source # return :: a -> MaybeErr err a Source #
Functor (MaybeErr err) # |
Instance details Defined in Maybes Methods fmap :: (a -> b) -> MaybeErr err a -> MaybeErr err b Source # (<$) :: a -> MaybeErr err b -> MaybeErr err a Source #
Applicative (MaybeErr err) # |
Instance details Defined in Maybes Methods pure :: a -> MaybeErr err a Source # (<*>) :: MaybeErr err (a -> b) -> MaybeErr err a -> MaybeErr err b Source # liftA2 :: (a -> b -> c) -> MaybeErr err a -> MaybeErr err b -> MaybeErr err c Source # (*>) :: MaybeErr err a -> MaybeErr err b -> MaybeErr err b Source # (<*) :: MaybeErr err a -> MaybeErr err b -> MaybeErr err a Source #

failME :: err -> MaybeErr err val #

isSuccess :: MaybeErr err val -> Bool #

orElse :: Maybe a -> a -> a infixr 4 #

Flipped version of `fromMaybe`, useful for chaining.

firstJust :: Maybe a -> Maybe a -> Maybe a #

firstJusts :: [Maybe a] -> Maybe a #

Takes a list of `Maybes` and returns the first `Just` if there is one, or `Nothing` otherwise.

whenIsJust :: Monad m => Maybe a -> (a -> m ()) -> m () #

expectJust :: HasCallStack => String -> Maybe a -> a #

rightToMaybe :: Either a b -> Maybe b #

# MaybeT

newtype MaybeT (m :: Type -> Type) a Source #

The parameterizable maybe monad, obtained by composing an arbitrary monad with the `Maybe` monad.

Computations are actions that may produce a value or exit.

The `return` function yields a computation that produces that value, while `>>=` sequences two subcomputations, exiting if either computation does.

Constructors

MaybeT |
Fields runMaybeT :: m (Maybe a)

#### Instances

Instances details

MonadTrans MaybeT |
Instance details Defined in Control.Monad.Trans.Maybe Methods lift :: Monad m => m a -> MaybeT m a Source #
Monad m => Monad (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods (>>=) :: MaybeT m a -> (a -> MaybeT m b) -> MaybeT m b Source # (>>) :: MaybeT m a -> MaybeT m b -> MaybeT m b Source # return :: a -> MaybeT m a Source #
Functor m => Functor (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods fmap :: (a -> b) -> MaybeT m a -> MaybeT m b Source # (<$) :: a -> MaybeT m b -> MaybeT m a Source #
MonadFix m => MonadFix (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods mfix :: (a -> MaybeT m a) -> MaybeT m a Source #
Monad m => MonadFail (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods fail :: String -> MaybeT m a Source #
(Functor m, Monad m) => Applicative (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods pure :: a -> MaybeT m a Source # (<*>) :: MaybeT m (a -> b) -> MaybeT m a -> MaybeT m b Source # liftA2 :: (a -> b -> c) -> MaybeT m a -> MaybeT m b -> MaybeT m c Source # (*>) :: MaybeT m a -> MaybeT m b -> MaybeT m b Source # (<*) :: MaybeT m a -> MaybeT m b -> MaybeT m a Source #
Foldable f => Foldable (MaybeT f) |
Instance details Defined in Control.Monad.Trans.Maybe Methods fold :: Monoid m => MaybeT f m -> m Source # foldMap :: Monoid m => (a -> m) -> MaybeT f a -> m Source # foldMap' :: Monoid m => (a -> m) -> MaybeT f a -> m Source # foldr :: (a -> b -> b) -> b -> MaybeT f a -> b Source # foldr' :: (a -> b -> b) -> b -> MaybeT f a -> b Source # foldl :: (b -> a -> b) -> b -> MaybeT f a -> b Source # foldl' :: (b -> a -> b) -> b -> MaybeT f a -> b Source # foldr1 :: (a -> a -> a) -> MaybeT f a -> a Source # foldl1 :: (a -> a -> a) -> MaybeT f a -> a Source # toList :: MaybeT f a -> [a] Source # null :: MaybeT f a -> Bool Source # length :: MaybeT f a -> Int Source # elem :: Eq a => a -> MaybeT f a -> Bool Source # maximum :: Ord a => MaybeT f a -> a Source # minimum :: Ord a => MaybeT f a -> a Source # sum :: Num a => MaybeT f a -> a Source # product :: Num a => MaybeT f a -> a Source #
Traversable f => Traversable (MaybeT f) |
Instance details Defined in Control.Monad.Trans.Maybe Methods traverse :: Applicative f0 => (a -> f0 b) -> MaybeT f a -> f0 (MaybeT f b) Source # sequenceA :: Applicative f0 => MaybeT f (f0 a) -> f0 (MaybeT f a) Source # mapM :: Monad m => (a -> m b) -> MaybeT f a -> m (MaybeT f b) Source # sequence :: Monad m => MaybeT f (m a) -> m (MaybeT f a) Source #
Contravariant m => Contravariant (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods contramap :: (a -> b) -> MaybeT m b -> MaybeT m a Source # (>$) :: b -> MaybeT m b -> MaybeT m a Source #
Eq1 m => Eq1 (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods liftEq :: (a -> b -> Bool) -> MaybeT m a -> MaybeT m b -> Bool Source #
Ord1 m => Ord1 (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods liftCompare :: (a -> b -> Ordering) -> MaybeT m a -> MaybeT m b -> Ordering Source #
Read1 m => Read1 (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (MaybeT m a) Source # liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [MaybeT m a] Source # liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (MaybeT m a) Source # liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [MaybeT m a] Source #
Show1 m => Show1 (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> MaybeT m a -> ShowS Source # liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [MaybeT m a] -> ShowS Source #
MonadZip m => MonadZip (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods mzip :: MaybeT m a -> MaybeT m b -> MaybeT m (a, b) Source # mzipWith :: (a -> b -> c) -> MaybeT m a -> MaybeT m b -> MaybeT m c Source # munzip :: MaybeT m (a, b) -> (MaybeT m a, MaybeT m b) Source #
MonadIO m => MonadIO (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods liftIO :: IO a -> MaybeT m a Source #
(Functor m, Monad m) => Alternative (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods empty :: MaybeT m a Source # (<|>) :: MaybeT m a -> MaybeT m a -> MaybeT m a Source # some :: MaybeT m a -> MaybeT m [a] Source # many :: MaybeT m a -> MaybeT m [a] Source #
Monad m => MonadPlus (MaybeT m) |
Instance details Defined in Control.Monad.Trans.Maybe Methods mzero :: MaybeT m a Source # mplus :: MaybeT m a -> MaybeT m a -> MaybeT m a Source #
(Monad m, HasDynFlags m) => HasDynFlags (MaybeT m) # |
Instance details Defined in DynFlags Methods getDynFlags :: MaybeT m DynFlags #
(Eq1 m, Eq a) => Eq (MaybeT m a) |
Instance details Defined in Control.Monad.Trans.Maybe Methods (==) :: MaybeT m a -> MaybeT m a -> Bool # (/=) :: MaybeT m a -> MaybeT m a -> Bool #
(Ord1 m, Ord a) => Ord (MaybeT m a) |
Instance details Defined in Control.Monad.Trans.Maybe Methods compare :: MaybeT m a -> MaybeT m a -> Ordering # (<) :: MaybeT m a -> MaybeT m a -> Bool # (<=) :: MaybeT m a -> MaybeT m a -> Bool # (>) :: MaybeT m a -> MaybeT m a -> Bool # (>=) :: MaybeT m a -> MaybeT m a -> Bool # max :: MaybeT m a -> MaybeT m a -> MaybeT m a # min :: MaybeT m a -> MaybeT m a -> MaybeT m a #
(Read1 m, Read a) => Read (MaybeT m a) |
Instance details Defined in Control.Monad.Trans.Maybe Methods readsPrec :: Int -> ReadS (MaybeT m a) Source # readList :: ReadS [MaybeT m a] Source # readPrec :: ReadPrec (MaybeT m a) Source # readListPrec :: ReadPrec [MaybeT m a] Source #
(Show1 m, Show a) => Show (MaybeT m a) |
Instance details Defined in Control.Monad.Trans.Maybe Methods showsPrec :: Int -> MaybeT m a -> ShowS Source # show :: MaybeT m a -> String Source # showList :: [MaybeT m a] -> ShowS Source #

liftMaybeT :: Monad m => m a -> MaybeT m a #

tryMaybeT :: IO a -> MaybeT IO a #

Try performing an `IO` action, failing on error.