Last active
December 16, 2015 22:29
-
-
Save blancas/5507033 to your computer and use it in GitHub Desktop.
stateful map with a state monad
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
(use '[blancas.morph core monads]) | |
(def cards [{:balance 30} {:balance 25}]) | |
(def due 100) | |
(run-state (mapm #(monad [due get-state | |
app (state (min due (:balance %))) | |
_ (put-state (- due app))] | |
(state (assoc % :applied-balance app))) cards) due) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment