Hoogle Search
Within LTS Haskell 24.3 (ghc-9.10.2)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
maybe :: b -> (a -> b) -> Maybe a -> bghc-lib-parser GHC.Data.Strict No documentation available.
maybe :: b -> (a -> b) -> Maybe a -> bghc-lib-parser GHC.Prelude.Basic 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 ""
maybe :: Decoder a -> Decoder (Maybe a)dhall Dhall.Marshal.Decode Decode a Maybe.
>>> input (maybe natural) "Some 1" Just 1
maybe :: b -> (a -> b) -> Maybe a -> bfoundation Foundation 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 ""
maybe :: b -> (a -> b) -> Maybe a -> bprelude-compat Prelude2010 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 ""
maybe :: b -> (a -> b) -> Maybe a -> bmixed-types-num Numeric.MixedTypes.PreludeHiding 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 ""
maybe :: b -> (a -> b) -> Maybe a -> bLambdaHack 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 ""
maybe :: b -> (a -> b) -> Maybe a -> bcabal-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 ""
maybe :: b -> (a -> b) -> Maybe a -> bincipit-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 ""
maybe :: (SymVal a, SymVal b) => SBV b -> (SBV a -> SBV b) -> SMaybe a -> SBV bsbv 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.