~ruther/guix-local

593c3fe600a5f5e90a6eea3a175f83d3319b4efe — Ludovic Courtès 12 years ago f7faff8
monads: Fix 'anym'.

* guix/monads.scm (anym): Fix successful case.
* tests/monads.scm ("anym"): New test.
2 files changed, 16 insertions(+), 3 deletions(-)

M guix/monads.scm
M tests/monads.scm
M guix/monads.scm => guix/monads.scm +4 -3
@@ 228,9 228,10 @@ lifted in MONAD, for which PROC returns true."
        (()
         (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

M tests/monads.scm => tests/monads.scm +12 -0
@@ 163,6 163,18 @@
         %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")