diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-03-18 23:15:51 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-03-18 23:15:51 +0100 |
commit | ce37a5b43f7f392c5c5b199ca5e93a5982c883ed (patch) | |
tree | 224bb829b2a2672725bded70efc1d5b79431a99a | |
parent | Update readme. (diff) | |
download | scheme-monad-ce37a5b43f7f392c5c5b199ca5e93a5982c883ed.tar.gz scheme-monad-ce37a5b43f7f392c5c5b199ca5e93a5982c883ed.tar.xz |
Simplified (monad state) modify.
-rw-r--r-- | monad/state.scm | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/monad/state.scm b/monad/state.scm index 40c9ff5..c607765 100644 --- a/monad/state.scm +++ b/monad/state.scm @@ -77,11 +77,9 @@ "Sets st to v." (list '() v)) -(define-stateful ((modify proc) st-list) +(define (modify proc) "Applies proc to the value stored in state, and stores it back" - (match st-list - ((r s) - (list '() (proc s))))) + (>>= (<$> proc (get)) put)) (define-method (run-state (st <state>) init) "Exec state with init as starting state value and st." |