combinators: Fix any-of and juxt

pull/3/head
Luis Guilherme Coelho 2024-02-19 21:41:35 -03:00
parent e8f0c30402
commit 2602e1d3de
No known key found for this signature in database
GPG Key ID: 1F2E76ACE3F531C8
1 changed files with 10 additions and 7 deletions

View File

@ -18,11 +18,13 @@ element of LST satisfies PRED."
(define (any-of pred) (define (any-of pred)
"Returns a procedure that takes a list LST and returns #t if any element of "Returns a procedure that takes a list LST and returns #t if any element of
LST satisfies PRED." LST satisfies PRED."
(match-lambda (lambda (lst)
(() #f) (let loop ((lst lst))
((head . tail) (match
(cond ((pred head) #t) ('() #f)
(else (any? pred tail)))))) ((head . tail)
(cond ((pred head) #t)
(else (loop tail))))))))
(define (conjoin . predicates) (define (conjoin . predicates)
"Returns a procedure that is the conjuction of every predicate in PREDICATES. "Returns a procedure that is the conjuction of every predicate in PREDICATES.
@ -77,5 +79,6 @@ of aditional arguments."
"Returns a procedure that is the juxtaposition of it's argument procedures. "Returns a procedure that is the juxtaposition of it's argument procedures.
The returned procedure takes a variable number of args, and returns a list The returned procedure takes a variable number of args, and returns a list
containing the result of applying each procedure to the args (left-to-right)." containing the result of applying each procedure to the args (left-to-right)."
(map (partial (flip apply) args) (lambda args
(cons proc more-procs))) (map (partial (flip apply) args)
(cons proc more-procs))))