Hoogle Search

Within LTS Haskell 24.46 (ghc-9.10.3)

Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.

  1. traceMaybe :: forall (m :: Type -> Type) a b . Monad m => (a -> Maybe b) -> Tracer m b -> Tracer m a

    contra-tracer Control.Tracer

    Run a tracer only for the Just variant of a Maybe. If it's Nothing, the nullTracer is used (no output). The arrow representation allows for proper laziness: if the tracer parameter does not produce any tracing effects, then the predicate won't even be evaluated. Contrast with the simple contravariant representation as a -> m (), in which the predicate _must_ be forced no matter what, because it's impossible to know a priori whether that function will not produce any tracing effects. It's written out explicitly for demonstration. Could also use arrow notation:

    traceMaybe p tr = Tracer $ proc a -> do
    case k a of
    Just b  -> use tr        -< b
    Nothing -> Arrow.squelch -< ()
    

  2. traceMaybeM :: Monad m => (a -> m (Maybe b)) -> Tracer m b -> Tracer m a

    contra-tracer Control.Tracer

    A monadic version of traceMaybe.

  3. mapMaybeWithKey :: GCompare k2 => (forall (v :: k1) . () => k2 v -> f v -> Maybe (g v)) -> MonoidalDMap k2 f -> MonoidalDMap k2 g

    dependent-monoidal-map Data.Dependent.Map.Monoidal

    O(n). Map keys/values and collect the Just results.

  4. fromMaybe :: a -> Maybe a -> a

    distribution-opensuse OpenSuse.Prelude

    The fromMaybe function takes a default value and a Maybe value. If the Maybe is Nothing, it returns the default value; otherwise, it returns the value contained in the Maybe.

    Examples

    Basic usage:
    >>> fromMaybe "" (Just "Hello, World!")
    "Hello, World!"
    
    >>> fromMaybe "" Nothing
    ""
    
    Read an integer from a string using readMaybe. If we fail to parse an integer, we want to return 0 by default:
    >>> import GHC.Internal.Text.Read ( readMaybe )
    
    >>> fromMaybe 0 (readMaybe "5")
    5
    
    >>> fromMaybe 0 (readMaybe "")
    0
    

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

    distribution-opensuse OpenSuse.Prelude

    Monadic generalisation of fromMaybe.

  6. mapMaybeM :: Monad m => (a -> m (Maybe b)) -> [a] -> m [b]

    distribution-opensuse OpenSuse.Prelude

    A version of mapMaybe that works with a monadic predicate.

  7. whenMaybe :: Applicative m => Bool -> m a -> m (Maybe a)

    distribution-opensuse OpenSuse.Prelude

    Like when, but return either Nothing if the predicate was False, or Just with the result of the computation.

    whenMaybe True  (print 1) == fmap Just (print 1)
    whenMaybe False (print 1) == pure Nothing
    

  8. whenMaybeM :: Monad m => m Bool -> m a -> m (Maybe a)

    distribution-opensuse OpenSuse.Prelude

    Like whenMaybe, but where the test can be monadic.

  9. toMaybe :: Bool -> a -> Maybe a

    dsp DSP.Basic

    generates a Just if the given condition holds

  10. throwMaybe :: forall (m :: Type -> Type) e a . Monad m => MSF (ExceptT e m) (Maybe e) (Maybe a)

    dunai Control.Monad.Trans.MSF.Except

    When the input is Just e, throw the exception e. (Does not output any actual data.)

Page 271 of many | Previous | Next