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.

  1. fromMaybeX :: MaybeX a -> a

    clash-prelude Clash.XException.MaybeX

    Deconstruct MaybeX into an a - the opposite of toMaybeX. Be careful when using this function, because it might return an XException if the argument was IsX.

  2. fromMaybeM :: Monad m => m a -> m (Maybe a) -> m a

    distribution-opensuse OpenSuse.Prelude

    Monadic generalisation of fromMaybe.

  3. fromMaybeExceptT :: forall (m :: Type -> Type) x a . Monad m => x -> Maybe a -> ExceptT x m a

    from-sum Control.FromSum

    Lift a Maybe to an ExceptT with a default value for the case when the Maybe is Nothing. If the Maybe is Just, then just return the value like normal:

    >>> let justVal = Just True :: Maybe Bool
    
    >>> fromMaybeExceptT 5 justVal :: ExceptT Int Identity Bool
    ExceptT (Identity (Right True))
    
    If the Maybe is Nothing, then use the default value as the error value:
    >>> let nothingVal = Nothing :: Maybe Bool
    
    >>> fromMaybeExceptT 5 nothingVal :: ExceptT Int Identity Bool
    ExceptT (Identity (Left 5))
    

  4. fromMaybeM :: Applicative m => m a -> Maybe a -> m a

    from-sum Control.FromSum

    A monadic version of fromMaybe.

    fromMaybeM nothingAction === maybe nothingAction pure
    
    >>> fromMaybeM [] $ Just 5
    [5]
    
    >>> fromMaybeM [] Nothing
    []
    

  5. fromMaybeMExceptT :: Monad m => x -> m (Maybe a) -> ExceptT x m a

    from-sum Control.FromSum

    Similar to fromMaybeExceptT except the Maybe value is lifted in a Monad.

    >>> let identityNothing = Identity Nothing :: Identity (Maybe Bool)
    
    >>> fromMaybeMExceptT 5 identityNothing :: ExceptT Int Identity Bool
    ExceptT (Identity (Left 5))
    

  6. fromMaybeMM :: Monad m => m a -> m (Maybe a) -> m a

    from-sum Control.FromSum

    Similar to fromMaybeM but the Maybe argument is also a monadic value.

    >>> fromMaybeMM [] [Just 6, Just 5]
    [6,5]
    
    >>> fromMaybeMM [] [Just 6, Nothing, Just 7]
    [6,7]
    
    NOTE: I don't particularly like the name of this function. If you have a suggestion for a better name, please submit a PR or issue.

  7. fromMaybeM_ :: (Applicative m, Monoid b) => m b -> Maybe a -> m b

    from-sum Control.FromSum

    Similar to fromMaybeM, but only run the monadic nothingAction if the Maybe argument is Nothing. Otherwise, return pure mempty.

    fromMaybeM_ nothingAction === maybe nothingAction (const $ pure mempty)
    
    >>> fromMaybeM_ (putStrLn "hello" >> pure "bye") $ Just 5
    ""
    
    >>> fromMaybeM_ (putStrLn "hello" >> pure "bye") Nothing
    hello
    "bye"
    
    This can be convenient when you want to run some sort of logging function whenever a Maybe is Nothing. If you imagine the logging function is IO (), then the effective type of fromMaybeM_ becomes fromMaybeM_ :: IO () -> Maybe a -> IO (), because () has a Monoid instance, and IO, has an Applicative instance.
    >>> fromMaybeM_ (putStrLn "hello") Nothing
    hello
    

  8. fromMaybeOr :: Maybe a -> a -> a

    from-sum Control.FromSum

    A fliped version of fromMaybe.

  9. fromMaybeOrExceptT :: forall (m :: Type -> Type) a x . Monad m => Maybe a -> x -> ExceptT x m a

    from-sum Control.FromSum

    Just like fromMaybeExceptT but with the arguments flipped.

  10. fromMaybeOrM :: Applicative m => Maybe a -> m a -> m a

    from-sum Control.FromSum

    A fliped version of fromMaybeM.

    >>> fromMaybeOrM (Just 5) []
    [5]
    
    This can be nice to use as an error handler.
    >>> fromMaybeOrM (Just 5) $ putStrLn "some error occurred" >> undefined
    5
    
    >>> fromMaybeOrM (Nothing) $ putStrLn "some error occurred" >> undefined
    some error occurred
    ...
    

Page 7 of many | Previous | Next