From ce37a5b43f7f392c5c5b199ca5e93a5982c883ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 18 Mar 2019 23:15:51 +0100 Subject: Simplified (monad state) modify. --- monad/state.scm | 6 ++---- 1 file 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 ) init) "Exec state with init as starting state value and st." -- cgit v1.2.3