Created
April 16, 2019 22:21
-
-
Save ClathomasPrime/25c28df822353a1bd8d0131825986f5f to your computer and use it in GitHub Desktop.
MonadState code which only "actually" alters state if some subcomputation succedes
This file contains 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
performIfSuccedes :: MonadState s m => m (Maybe a) -> m (Maybe a) | |
performIfSuccedes m = do | |
s <- get | |
res <- m | |
case res of | |
Nothing -> put s >> return Nothing | |
Just a -> return (Just a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment