Last active
June 21, 2021 02:29
-
-
Save vst/a1a49e0047c8fd24adbd1759bd14f864 to your computer and use it in GitHub Desktop.
Haskell Auxiliary Function: ifM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | See https://gist.github.com/vst/a1a49e0047c8fd24adbd1759bd14f864 | |
-- | |
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