aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2025-01-17 16:13:33 +0000
committerArun Isaac2025-01-20 01:47:03 +0000
commit04595bbd1f372aeefbe87994ff592c515f7a0482 (patch)
tree739e195442fbde6592797a03dca7103d91da2081
parentb2cfe8a9d18d658fc54139721a42f500c9520e23 (diff)
downloadravanan-04595bbd1f372aeefbe87994ff592c515f7a0482.tar.gz
ravanan-04595bbd1f372aeefbe87994ff592c515f7a0482.tar.lz
ravanan-04595bbd1f372aeefbe87994ff592c515f7a0482.zip
monads: Add mmap.
* ravanan/work/monads.scm (mmap): New function. (state-map): New public function.
-rw-r--r--ravanan/work/monads.scm9
1 files changed, 9 insertions, 0 deletions
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>
(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)