From 04595bbd1f372aeefbe87994ff592c515f7a0482 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Fri, 17 Jan 2025 16:13:33 +0000 Subject: monads: Add mmap. * ravanan/work/monads.scm (mmap): New function. (state-map): New public function. --- ravanan/work/monads.scm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ravanan/work/monads.scm b/ravanan/work/monads.scm index 830e7ce..a5aea5f 100644 --- a/ravanan/work/monads.scm +++ b/ravanan/work/monads.scm @@ -40,6 +40,7 @@ state-let* state-begin state-sequence + state-mmap current-state set-current-state run-with-state)) @@ -85,6 +86,11 @@ of values." mvalues))) (return (reverse reverse-list))))) +(define (mmap monad-type mproc . lists) + "Map monadic funcion @var{mproc} in @var{monad-type} over @var{lists} and return +a monadic list." + (sequence monad-type (apply map mproc lists))) + (define-immutable-record-type (maybe value valid?) maybe? @@ -243,6 +249,9 @@ maybe-monadic." (define state-sequence (cut sequence %state-monad <>)) +(define state-map + (cut mmap %state-monad <> <...>)) + (define (current-state) "Return the current state as a state-monadic value." (lambda (state) -- cgit v1.2.3