summaryrefslogtreecommitdiffstats
path: root/collect.scm
diff options
context:
space:
mode:
Diffstat (limited to 'collect.scm')
-rw-r--r--collect.scm31
1 files changed, 17 insertions, 14 deletions
diff --git a/collect.scm b/collect.scm
index 05bc2cf..d4ccb6f 100644
--- a/collect.scm
+++ b/collect.scm
@@ -117,20 +117,23 @@
)
;@
(define (reduce <proc> <seed> . <collections>)
- (let ( (max+1 (collect:size (car <collections>)))
- (generators (map collect:gen-elts <collections>))
- )
- (let loop ( (count 0) )
- (cond
- ((< count max+1)
- (set! <seed>
- (apply <proc> <seed> (map (lambda (g) (g)) generators)))
- (loop (collect:add1 count))
- )
- (else <seed>)
- ) )
-) )
-
+ (define (reduce-init pred? init lst)
+ (if (null? lst)
+ init
+ (reduce-init pred? (pred? init (car lst)) (cdr lst))))
+ (if (null? <collections>)
+ (cond ((null? <seed>) <seed>)
+ ((null? (cdr <seed>)) (car <seed>))
+ (else (reduce-init <proc> (car <seed>) (cdr <seed>))))
+ (let ((max+1 (collect:size (car <collections>)))
+ (generators (map collect:gen-elts <collections>)))
+ (let loop ((count 0))
+ (cond
+ ((< count max+1)
+ (set! <seed>
+ (apply <proc> <seed> (map (lambda (g) (g)) generators)))
+ (loop (collect:add1 count)))
+ (else <seed>))))))
;;@ pred true for every elt?