mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-12-24 05:18:07 -05:00
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
2 changed files with 16 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue