summaryrefslogtreecommitdiffstats
path: root/collect.scm
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2017-02-20 00:05:38 -0800
committerBryan Newbold <bnewbold@robocracy.org>2017-02-20 00:05:38 -0800
commit64f037d91e0c9296dcaef9a0ff3eb33b19a2ed34 (patch)
tree1b23b8e8005328194e2fb4bf653806c85050933f /collect.scm
parent5bea21e81ed516440e34e480f2c33ca41aa8c597 (diff)
downloadslib-64f037d91e0c9296dcaef9a0ff3eb33b19a2ed34.tar.gz
slib-64f037d91e0c9296dcaef9a0ff3eb33b19a2ed34.zip
Import Upstream version 3a5upstream/3a5
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?