monads: Fix 'anym'.
* guix/monads.scm (anym): Fix successful case. * tests/monads.scm ("anym"): New test.
This commit is contained in:
parent
f7faff88b7
commit
593c3fe600
|
@ -228,9 +228,10 @@ lifted in MONAD, for which PROC returns true."
|
||||||
(()
|
(()
|
||||||
(return #f))
|
(return #f))
|
||||||
((head tail ...)
|
((head tail ...)
|
||||||
(mlet monad ((value head))
|
(mlet* monad ((value head)
|
||||||
(or (and=> (proc value) return)
|
(result -> (proc value)))
|
||||||
head
|
(if result
|
||||||
|
(return result)
|
||||||
(loop tail))))))))
|
(loop tail))))))))
|
||||||
|
|
||||||
(define-syntax listm
|
(define-syntax listm
|
||||||
|
|
|
@ -163,6 +163,18 @@
|
||||||
%monads
|
%monads
|
||||||
%monad-run))
|
%monad-run))
|
||||||
|
|
||||||
|
(test-assert "anym"
|
||||||
|
(every (lambda (monad run)
|
||||||
|
(eq? (run (with-monad monad
|
||||||
|
(let ((lst (list (return 1) (return 2) (return 3))))
|
||||||
|
(anym monad
|
||||||
|
(lambda (x)
|
||||||
|
(and (odd? x) 'odd!))
|
||||||
|
lst))))
|
||||||
|
'odd!))
|
||||||
|
%monads
|
||||||
|
%monad-run))
|
||||||
|
|
||||||
(test-end "monads")
|
(test-end "monads")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue