Skip to content
Snippets Groups Projects
Commit 593c3fe6 authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

monads: Fix 'anym'.

* guix/monads.scm (anym): Fix successful case.
* tests/monads.scm ("anym"): New test.
parent f7faff88
No related branches found
No related tags found
No related merge requests found
...@@ -228,9 +228,10 @@ (define (anym monad proc lst) ...@@ -228,9 +228,10 @@ (define (anym monad proc lst)
(() (()
(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 @@ (define (frob i) ...@@ -163,6 +163,18 @@ (define (frob i)
%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")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment