We're updating the issue view to help you get more done. 

into does not work with IReduceInit

Description

This should work:

1 2 3 4 5 6 7 8 9 10 11 12 13 (into [] (reify clojure.lang.IReduceInit (reduce [_ f start] (reduce f start (range 10))))) IllegalArgumentException Don't know how to create ISeq from: user$eval5$reify__6 clojure.lang.RT.seqFrom (RT.java:506) clojure.lang.RT.seq (RT.java:487) clojure.core/seq--seq--4091 (core.clj:135) clojure.core.protocols/seq-reduce (protocols.clj:30) clojure.core.protocols/fn--6422 (protocols.clj:42) clojure.core.protocols/fn--6369/f--6255--auto----G--6364--6382 (protocols.clj:13) clojure.core/reduce (core.clj:6469) clojure.core/into (core.clj:6550)

Cause: CollReduce only supports IReduce, not IReduceInit so when reduce calls into it, it falls back to trying to obtain a seq representation which fails.

Proposed: Extend CollReduce to IReduceInit and in the non-init arity, cast to IReduce. Also, now that CollReduce supports both IReduceInit and Iterable, a coll that implements both makes the path through CollReduce nondeterministic. transduce does an explicit check that prefers IReduceInit - the patch copies that approach to reduce as well.

Another consequence of this change is that since PersistentVector implements IReduce but throws on the non-init path, there are some test breakages. To address this, (which implements the non-init reduce) must be applied first.

Patch: clj-1572-4.patch
Depends on: being applied first

Environment

None

Status

Assignee

Unassigned

Reporter

Alex Miller

Labels

Approval

Ok

Patch

Code and Test

Fix versions

Affects versions

Release 1.7

Priority

Major