aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ravanan/work/monads.scm12
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)