diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2017-02-20 00:05:38 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2017-02-20 00:05:38 -0800 |
commit | 64f037d91e0c9296dcaef9a0ff3eb33b19a2ed34 (patch) | |
tree | 1b23b8e8005328194e2fb4bf653806c85050933f /collect.scm | |
parent | 5bea21e81ed516440e34e480f2c33ca41aa8c597 (diff) | |
download | slib-64f037d91e0c9296dcaef9a0ff3eb33b19a2ed34.tar.gz slib-64f037d91e0c9296dcaef9a0ff3eb33b19a2ed34.zip |
Import Upstream version 3a5upstream/3a5
Diffstat (limited to 'collect.scm')
-rw-r--r-- | collect.scm | 31 |
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? |