Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using Alternative <|> to fold nested if
import Control.Monad
import Control.Applicative
checkProperty = undefined
getDmgMult t elem = maybe 1 id $ do
e <- elem
let check f = checkProperty t ((==e) . f) >>= guard
(check succ >> return 2) `mplus` (check pred >> return 0.5)
getDmgMult t elem = maybe 1 id $ do
e <- elem
let check f = checkProperty t ((==e) . f) >>= guard
2 <$ check succ <|> 0.5 <$ check pred
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment