Skip to content

Instantly share code, notes, and snippets.

@blancas
Last active December 16, 2015 22:29
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 blancas/5507033 to your computer and use it in GitHub Desktop.
Save blancas/5507033 to your computer and use it in GitHub Desktop.
stateful map with a state monad
(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