mirror of
https://github.com/correl/calrissian.git
synced 2024-11-23 11:09:58 +00:00
wip: modify-and-return
This commit is contained in:
parent
4db1e51ab7
commit
4ec1a9897d
2 changed files with 17 additions and 2 deletions
|
@ -35,6 +35,11 @@
|
||||||
(lambda (s)
|
(lambda (s)
|
||||||
(tuple 'ok (call inner-monad 'return (funcall f s))))))
|
(tuple 'ok (call inner-monad 'return (funcall f s))))))
|
||||||
|
|
||||||
|
(defun modify-and-return
|
||||||
|
((f (tuple 'state-transformer inner-monad))
|
||||||
|
(lambda (s)
|
||||||
|
(call inner-monad 'return (funcall f s)))))
|
||||||
|
|
||||||
(defun eval
|
(defun eval
|
||||||
((m s (tuple 'state-transformer inner-monad))
|
((m s (tuple 'state-transformer inner-monad))
|
||||||
(call inner-monad '>>=
|
(call inner-monad '>>=
|
||||||
|
|
|
@ -28,15 +28,25 @@
|
||||||
(call m 'modify (lambda (x) (* x 2))))
|
(call m 'modify (lambda (x) (* x 2))))
|
||||||
5))))
|
5))))
|
||||||
|
|
||||||
(deftest exec-modify-multiple
|
(deftest exec-put-and-modify
|
||||||
(is-equal 30
|
(is-equal 30
|
||||||
(let ((m (: state-transformer new 'identity-monad)))
|
(let ((m (: state-transformer new 'identity-monad)))
|
||||||
(call m 'exec
|
(call m 'exec
|
||||||
(do-m m
|
(do-m m
|
||||||
|
(call m 'put 10)
|
||||||
(call m 'modify (lambda (x) (+ x 5)))
|
(call m 'modify (lambda (x) (+ x 5)))
|
||||||
(call m 'modify (lambda (x) (* x 2)))
|
(call m 'modify (lambda (x) (* x 2)))
|
||||||
(call m 'return 123))
|
(call m 'return 123))
|
||||||
10))))
|
3))))
|
||||||
|
|
||||||
|
(deftest exec-bind-and-modify
|
||||||
|
(is-equal 16
|
||||||
|
(let ((m (: state-transformer new 'identity-monad)))
|
||||||
|
(call m 'exec
|
||||||
|
(do-m m
|
||||||
|
(a <- (call m 'modify-and-return (lambda (x) (+ x 5))))
|
||||||
|
(call m 'modify (lambda (x) (+ x a))))
|
||||||
|
3))))
|
||||||
|
|
||||||
(deftest exec-fail
|
(deftest exec-fail
|
||||||
(is-throw #(error value)
|
(is-throw #(error value)
|
||||||
|
|
Loading…
Reference in a new issue