diff options
author | Arun Isaac | 2025-01-20 01:46:12 +0000 |
---|---|---|
committer | Arun Isaac | 2025-01-20 01:47:22 +0000 |
commit | 11a575020b20f395f51d5715615abd9041c1ae55 (patch) | |
tree | cd2bb301c86592e35230c7f8226c12ffc35fdee7 | |
parent | 04595bbd1f372aeefbe87994ff592c515f7a0482 (diff) | |
download | ravanan-11a575020b20f395f51d5715615abd9041c1ae55.tar.gz ravanan-11a575020b20f395f51d5715615abd9041c1ae55.tar.lz ravanan-11a575020b20f395f51d5715615abd9041c1ae55.zip |
monads: Add mappend-map.
* ravanan/work/monads.scm (mappend-map): New function.
(state-append-map): New public function.
-rw-r--r-- | ravanan/work/monads.scm | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/ravanan/work/monads.scm b/ravanan/work/monads.scm index a5aea5f..fbc96cf 100644 --- a/ravanan/work/monads.scm +++ b/ravanan/work/monads.scm @@ -40,7 +40,8 @@ state-let* state-begin state-sequence - state-mmap + state-map + state-append-map current-state set-current-state run-with-state)) @@ -91,6 +92,12 @@ of values." a monadic list." (sequence monad-type (apply map mproc lists))) +(define (mappend-map monad-type mproc . lists) + "Map monadic funcion @var{mproc} in @var{monad-type} over @var{lists} like +@code{mmap}, but return a monadic list of the results appended together." + (mlet* monad-type ((mapped (apply mmap monad-type mproc lists))) + ((monad-return monad-type) (apply append mapped)))) + (define-immutable-record-type <maybe> (maybe value valid?) maybe? @@ -252,6 +259,9 @@ maybe-monadic." (define state-map (cut mmap %state-monad <> <...>)) +(define state-append-map + (cut mappend-map %state-monad <> <...>)) + (define (current-state) "Return the current state as a state-monadic value." (lambda (state) |