Skip to content

Instantly share code, notes, and snippets.

Last active Jun 21, 2021
What would you like to do?
Haskell Auxiliary Function: ifM
-- | See
import Data.Bool (bool)
-- | Monadic version of @if-then-else@.
-- >>> ifM (pure False) (pure "Nice") (pure "Oh no!")
-- "Oh no!"
-- >>> ifM (pure True) (pure "Nice") (pure "Oh no!")
-- "Nice"
ifM :: Monad m => m Bool -> m a -> m a -> m a
ifM p t f = p >>= bool f t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment