Similar to fromMaybe but with flipped arguments.
readMaybe "True" ?: FalseTrue
readMaybe "Tru" ?: FalseFalse
:: a typeCtrl KGHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05
Modulerelude-1.2.0.0Haskell2010
SPDX-License-Identifier : MIT Maintainer : Kowainik xrom.xkov@gmail.com Stability : Stable Portability : Portable
Utility functions to work with Relude.Maybe data type as monad.
Similar to fromMaybe but with flipped arguments.
readMaybe "True" ?: FalseTrue
readMaybe "Tru" ?: FalseFalse
Specialized version of Relude.for_ for Maybe. It's used for code readability.
Also helps to avoid space leaks: Foldable.mapM_ space leak.
whenJust Nothing $ \b -> print (not b)whenJust (Just True) $ \b -> print (not b)False
Monadic version of whenJust.
whenJustM (pure Nothing) $ \b -> print (not b)whenJustM (pure $ Just True) $ \b -> print (not b)False
Performs default Applicative action if Nothing is given. Otherwise returns content of Just pured to Applicative.
whenNothing Nothing [True, False][True,False]whenNothing (Just True) [True, False][True]
Performs default Applicative action if Nothing is given. Do nothing for Just. Convenient for discarding Just content.
whenNothing_ Nothing $ putTextLn "Nothing!"Nothing!whenNothing_ (Just True) $ putTextLn "Nothing!"
Monadic version of whenNothing.
whenNothingM (pure $ Just True) $ True <$ putTextLn "Is Just!"TruewhenNothingM (pure Nothing) $ False <$ putTextLn "Is Nothing!"Is Nothing!False
Monadic version of whenNothing_.
whenNothingM_ (pure $ Just True) $ putTextLn "Is Just!"whenNothingM_ (pure Nothing) $ putTextLn "Is Nothing!"Is Nothing!
The monadic version of the mapMaybe function.
:{evenInHalf :: Int -> IO (Maybe Int)evenInHalf n | even n = pure $ Just $ n `div` 2 | otherwise = pure Nothing:}
mapMaybeM evenInHalf [1..10][1,2,3,4,5]