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. maybe :: b -> (a -> b) -> Maybe a -> b

    LambdaHack Game.LambdaHack.Core.Prelude

    The maybe function takes a default value, a function, and a Maybe value. If the Maybe value is Nothing, the function returns the default value. Otherwise, it applies the function to the value inside the Just and returns the result.

    Examples

    Basic usage:
    >>> maybe False odd (Just 3)
    True
    
    >>> maybe False odd Nothing
    False
    
    Read an integer from a string using readMaybe. If we succeed, return twice the integer; that is, apply (*2) to it. If instead we fail to parse an integer, return 0 by default:
    >>> import GHC.Internal.Text.Read ( readMaybe )
    
    >>> maybe 0 (*2) (readMaybe "5")
    10
    
    >>> maybe 0 (*2) (readMaybe "")
    0
    
    Apply show to a Maybe Int. If we have Just n, we want to show the underlying Int n. But if we have Nothing, we return the empty string instead of (for example) "Nothing":
    >>> maybe "" show (Just 5)
    "5"
    
    >>> maybe "" show Nothing
    ""
    

  2. maybe :: b -> (a -> b) -> Maybe a -> b

    cabal-install-solver Distribution.Solver.Compat.Prelude

    The maybe function takes a default value, a function, and a Maybe value. If the Maybe value is Nothing, the function returns the default value. Otherwise, it applies the function to the value inside the Just and returns the result.

    Examples

    Basic usage:
    >>> maybe False odd (Just 3)
    True
    
    >>> maybe False odd Nothing
    False
    
    Read an integer from a string using readMaybe. If we succeed, return twice the integer; that is, apply (*2) to it. If instead we fail to parse an integer, return 0 by default:
    >>> import GHC.Internal.Text.Read ( readMaybe )
    
    >>> maybe 0 (*2) (readMaybe "5")
    10
    
    >>> maybe 0 (*2) (readMaybe "")
    0
    
    Apply show to a Maybe Int. If we have Just n, we want to show the underlying Int n. But if we have Nothing, we return the empty string instead of (for example) "Nothing":
    >>> maybe "" show (Just 5)
    "5"
    
    >>> maybe "" show Nothing
    ""
    

  3. maybe :: b -> (a -> b) -> Maybe a -> b

    incipit-base Incipit.Base

    The maybe function takes a default value, a function, and a Maybe value. If the Maybe value is Nothing, the function returns the default value. Otherwise, it applies the function to the value inside the Just and returns the result.

    Examples

    Basic usage:
    >>> maybe False odd (Just 3)
    True
    
    >>> maybe False odd Nothing
    False
    
    Read an integer from a string using readMaybe. If we succeed, return twice the integer; that is, apply (*2) to it. If instead we fail to parse an integer, return 0 by default:
    >>> import GHC.Internal.Text.Read ( readMaybe )
    
    >>> maybe 0 (*2) (readMaybe "5")
    10
    
    >>> maybe 0 (*2) (readMaybe "")
    0
    
    Apply show to a Maybe Int. If we have Just n, we want to show the underlying Int n. But if we have Nothing, we return the empty string instead of (for example) "Nothing":
    >>> maybe "" show (Just 5)
    "5"
    
    >>> maybe "" show Nothing
    ""
    

  4. maybe :: (SymVal a, SymVal b) => SBV b -> (SBV a -> SBV b) -> SMaybe a -> SBV b

    sbv Data.SBV.Maybe

    Case analysis for symbolic Maybes. If the value isNothing, return the default value; if it isJust, apply the function.

    >>> maybe 0 (`sMod` 2) (sJust (3 :: SInteger))
    1 :: SInteger
    
    >>> maybe 0 (`sMod` 2) (sNothing :: SMaybe Integer)
    0 :: SInteger
    
    >>> let f = uninterpret "f" :: SInteger -> SBool
    
    >>> prove $ \x d -> maybe d f (sJust x) .== f x
    Q.E.D.
    
    >>> prove $ \d -> maybe d f sNothing .== d
    Q.E.D.
    

  5. maybe :: forall (m :: Type -> Type) a b . Monad m => (a -> Maybe b) -> Fold m a (Maybe b)

    streamly-core Streamly.Internal.Data.Fold

    Consume a single input and transform it using the supplied Maybe returning function. Pre-release

  6. maybe :: forall (m :: Type -> Type) a b . Monad m => (a -> Maybe b) -> Parser a m b

    streamly-core Streamly.Internal.Data.Parser

    Map a Maybe returning function on the next element in the stream. The parser fails if the function returns Nothing otherwise returns the Just value.

    >>> toEither = Maybe.maybe (Left "maybe: predicate failed") Right
    
    >>> maybe f = Parser.either (toEither . f)
    
    >>> maybe f = Parser.fromFoldMaybe "maybe: predicate failed" (Fold.maybe f)
    
    Pre-release

  7. maybe :: Decoder a -> Decoder (Maybe a)

    aeson-combinators Data.Aeson.Combinators.Decode

    Try a decoder and get back a 'Just a' if it succeeds and Nothing if it fails. In other words, this decoder always succeeds with a 'Maybe a' value.

    >>> decode (maybe string) "42"
    Just Nothing
    
    >>> decode (maybe int) "42"
    Just (Just 42)
    

  8. maybe :: b -> (a -> b) -> Maybe a -> b

    clash-prelude Clash.HaskellPrelude

    The maybe function takes a default value, a function, and a Maybe value. If the Maybe value is Nothing, the function returns the default value. Otherwise, it applies the function to the value inside the Just and returns the result.

    Examples

    Basic usage:
    >>> maybe False odd (Just 3)
    True
    
    >>> maybe False odd Nothing
    False
    
    Read an integer from a string using readMaybe. If we succeed, return twice the integer; that is, apply (*2) to it. If instead we fail to parse an integer, return 0 by default:
    >>> import GHC.Internal.Text.Read ( readMaybe )
    
    >>> maybe 0 (*2) (readMaybe "5")
    10
    
    >>> maybe 0 (*2) (readMaybe "")
    0
    
    Apply show to a Maybe Int. If we have Just n, we want to show the underlying Int n. But if we have Nothing, we return the empty string instead of (for example) "Nothing":
    >>> maybe "" show (Just 5)
    "5"
    
    >>> maybe "" show Nothing
    ""
    

  9. maybe :: Memo a -> Memo (Maybe a)

    data-memocombinators Data.MemoCombinators

    No documentation available.

  10. maybe :: b -> (a -> b) -> Maybe a -> b

    dimensional Numeric.Units.Dimensional.Prelude

    The maybe function takes a default value, a function, and a Maybe value. If the Maybe value is Nothing, the function returns the default value. Otherwise, it applies the function to the value inside the Just and returns the result.

    Examples

    Basic usage:
    >>> maybe False odd (Just 3)
    True
    
    >>> maybe False odd Nothing
    False
    
    Read an integer from a string using readMaybe. If we succeed, return twice the integer; that is, apply (*2) to it. If instead we fail to parse an integer, return 0 by default:
    >>> import GHC.Internal.Text.Read ( readMaybe )
    
    >>> maybe 0 (*2) (readMaybe "5")
    10
    
    >>> maybe 0 (*2) (readMaybe "")
    0
    
    Apply show to a Maybe Int. If we have Just n, we want to show the underlying Int n. But if we have Nothing, we return the empty string instead of (for example) "Nothing":
    >>> maybe "" show (Just 5)
    "5"
    
    >>> maybe "" show Nothing
    ""
    

Page 11 of many | Previous | Next