Created
March 15, 2019 21:14
-
-
Save chris-martin/47c6df16482bd54a159cac04938b2b88 to your computer and use it in GitHub Desktop.
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
{-# LANGUAGE LambdaCase #-} | |
import Prelude (Bool (True, False), Monad, (>>=)) | |
ifThenElseM :: Monad m => m Bool -> m a -> m a -> m a | |
ifThenElseM cond ifTrue ifFalse = | |
cond >>= \case { True -> ifTrue; False -> ifFalse } | |
ifThenElseM' :: Monad m => [(m Bool, m a)] -> m a -> m a | |
ifThenElseM' ifs ifAllFalse = | |
go ifs | |
where | |
go = \case | |
[] -> ifAllFalse | |
(cond, x) : xs -> ifThenElseM cond x (go xs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what are you doin over here chris