diff --git a/guix/monads.scm b/guix/monads.scm index b62fc28a559f6f59d83c998d0d76e3d1adbe6162..f5c9e8e9c7d871f24436c0c02d754b73e5989655 100644 --- a/guix/monads.scm +++ b/guix/monads.scm @@ -228,9 +228,10 @@ (define (anym monad proc lst) (() (return #f)) ((head tail ...) - (mlet monad ((value head)) - (or (and=> (proc value) return) - head + (mlet* monad ((value head) + (result -> (proc value))) + (if result + (return result) (loop tail)))))))) (define-syntax listm diff --git a/tests/monads.scm b/tests/monads.scm index 7fc2aa90c1c8b9eea325d11d396ed14cf801d578..d3f78e15684076d89976cd144ee95330d605e0c0 100644 --- a/tests/monads.scm +++ b/tests/monads.scm @@ -163,6 +163,18 @@ (define (frob i) %monads %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")