| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Bool
Description
Convenient commonly used and very helpful functions to work with
Bool and also with monads.
- bool :: a -> a -> Bool -> a
- guard :: Alternative f => Bool -> f ()
- guardM :: MonadPlus m => m Bool -> m ()
- ifM :: Monad m => m Bool -> m a -> m a -> m a
- unless :: Applicative f => Bool -> f () -> f ()
- unlessM :: Monad m => m Bool -> m () -> m ()
- when :: Applicative f => Bool -> f () -> f ()
- whenM :: Monad m => m Bool -> m () -> m ()
Documentation
bool :: a -> a -> Bool -> a Source #
Reversed version of if-then-else.
>>>bool 5 10 True10>>>bool 5 10 False5
guardM :: MonadPlus m => m Bool -> m () Source #
Monadic version of guard. Occasionally useful.
Here some complex but real-life example:
@
findSomePath :: IO (Maybe FilePath)
somePath :: MaybeT IO FilePath somePath = do path <- MaybeT findSomePath guardM $ liftIO $ doesDirectoryExist path return path @
ifM :: Monad m => m Bool -> m a -> m a -> m a Source #
Monadic version of if-then-else.
>>>ifM (pure True) (putText "True text") (putText "False text")True text
unless :: Applicative f => Bool -> f () -> f () #
The reverse of when.
unlessM :: Monad m => m Bool -> m () -> m () Source #
Monadic version of unless.
>>>unlessM (pure False) $ putText "No text :("No text :(>>>unlessM (pure True) $ putText "Yes text :)"
when :: Applicative f => Bool -> f () -> f () #
Conditional execution of Applicative expressions. For example,
when debug (putStrLn "Debugging")
will output the string Debugging if the Boolean value debug
is True, and otherwise do nothing.