wip: modify-and-return

This commit is contained in:
Correl Roush 2014-05-13 19:40:37 -04:00
parent 4db1e51ab7
commit 4ec1a9897d
2 changed files with 17 additions and 2 deletions

View file

@ -35,6 +35,11 @@
(lambda (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
((m s (tuple 'state-transformer inner-monad))
(call inner-monad '>>=

View file

@ -28,15 +28,25 @@
(call m 'modify (lambda (x) (* x 2))))
5))))
(deftest exec-modify-multiple
(deftest exec-put-and-modify
(is-equal 30
(let ((m (: state-transformer new 'identity-monad)))
(call m 'exec
(do-m m
(call m 'put 10)
(call m 'modify (lambda (x) (+ x 5)))
(call m 'modify (lambda (x) (* x 2)))
(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
(is-throw #(error value)