reduce dispatches to a reify's IReduceInit reduce method (jolt-z1zu)
(reduce f init (reify clojure.lang.IReduceInit (reduce [_ f i] ...))) tried to seq the reify and threw 'not seqable'. When the coll is a reify carrying a reduce method, drive the reduction through it. Corpus 2693->2694.
This commit is contained in:
parent
31a453d492
commit
f15a4e7747
2 changed files with 11 additions and 3 deletions
|
|
@ -178,7 +178,15 @@
|
|||
((f coll) (let ((s (jolt-seq coll)))
|
||||
(if (jolt-nil? s) (jolt-invoke f) ; (reduce f []) -> (f)
|
||||
(reduce-seq f (seq-first s) (jolt-seq (seq-more s))))))
|
||||
((f init coll) (reduce-seq f init (jolt-seq coll)))))
|
||||
((f init coll)
|
||||
;; IReduceInit: a reify/record with its own `reduce` method drives the
|
||||
;; reduction (reduce f init (reify clojure.lang.IReduceInit (reduce [_ f i] ...))).
|
||||
(cond
|
||||
((and (jreify? coll) (reified-methods coll)
|
||||
(hashtable-ref (reified-methods coll) "reduce" #f))
|
||||
=> (lambda (m) (let ((r (jolt-invoke m coll f init)))
|
||||
(if (jolt-reduced? r) (jolt-reduced-val r) r))))
|
||||
(else (reduce-seq f init (jolt-seq coll)))))))
|
||||
|
||||
(define (jolt-into to from) (reduce-seq (lambda (acc x) (jolt-conj1 acc x)) to (jolt-seq from)))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue