From 11a575020b20f395f51d5715615abd9041c1ae55 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Mon, 20 Jan 2025 01:46:12 +0000 Subject: monads: Add mappend-map. * ravanan/work/monads.scm (mappend-map): New function. (state-append-map): New public function. --- ravanan/work/monads.scm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 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) -- cgit v1.2.3