Skip to content

Instantly share code, notes, and snippets.

@chris-martin
Created March 15, 2019 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chris-martin/47c6df16482bd54a159cac04938b2b88 to your computer and use it in GitHub Desktop.
Save chris-martin/47c6df16482bd54a159cac04938b2b88 to your computer and use it in GitHub Desktop.
{-# 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)
@argumatronic
Copy link

what are you doin over here chris

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment