chickadee » srfi-127 » lseq-any

lseq-any pred lseq1 lseq2 ...procedure

Applies pred to successive elements of the lseqs, returning true if pred returns true on any application. If an application returns a true value, lseq-any immediately returns that value. Otherwise, it iterates until a true value is produced or one of the lseqs runs out of values; in the latter case, lseq-any returns #f. It is an error if pred does not accept the same number of arguments as there are lseqs and return a boolean result.

Note the difference between lseq-find and lseq-any -- lseq-find returns the element that satisfied the predicate; lseq-any returns the true value that the predicate produced.

Like lseq-every, lseq-any's name does not end with a question mark -- this is to indicate that it does not return a simple boolean (#t or #f), but a general value.

(lseq-any integer? '(a 3 b 2.7))       ;=> #t
(lseq-any integer? '(a 3.1 b 2.7))     ;=> #f
(lseq-any < '(3 1 4 1 5) '(2 7 1 8 2)) ;=> #t

(define (factorial n)
  (cond
    ((< n 0) #f)
    ((= n 0) 1)
    (else (* n (factorial (- n 1))))))
(lseq-any factorial '(-1 -2 3 4))      ;=> 6