diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-01-02 17:50:31 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-01-02 17:50:31 -0800 |
commit | b491768c9377f474c130b4b27b893ae9504929ac (patch) | |
tree | ae7c43dc0d7f34e6ce78c80250cbb29838f98229 /monads.lisp | |
parent | 376dc57915875861988cf6437d983a34670a2d02 (diff) | |
download | lisp-snippets-b491768c9377f474c130b4b27b893ae9504929ac.tar.gz lisp-snippets-b491768c9377f474c130b4b27b893ae9504929ac.tar.bz2 lisp-snippets-b491768c9377f474c130b4b27b893ae9504929ac.zip |
Add example for state transformer monad.
Diffstat (limited to 'monads.lisp')
-rw-r--r-- | monads.lisp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/monads.lisp b/monads.lisp index 8586f5b..0bda2ac 100644 --- a/monads.lisp +++ b/monads.lisp @@ -234,6 +234,19 @@ ;;; State transformer monad, with operations expressed using comprehensions ;;; over the identity monad, featuring multiple-value binding. ;;; +;;; Example: +;;; +;;; (let ((transformer (state-xform-comp (list x y z) +;;; (x (lambda (state) +;;; (values `(:stage x ,state) (1+ state)))) +;;; (y (lambda (state) +;;; (values `(:stage y ,state) (+ 10 state)))) +;;; (z (lambda (state) +;;; (values `(:stage z ,state) nil)))))) +;;; (funcall transformer 42)) +;;; +;;; -> ((:STAGE X 42) (:STAGE Y 43) (:STAGE Z 53)) +;;; (define-monad state-xform-monad :comprehension state-xform-comp :map ((f) |