Clojure

PersistentVector implements IReduce but the no init arity throws

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: Release 1.7
  • Fix Version/s: Release 1.7
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code and Test
  • Approval:
    Ok

Description

The reduce arity of IReduce in PersistentVector is implemented as: "throw new UnsupportedOperationException()".

After the CLJ-1572 patch is applied the following code will throw:

(reduce + [1 2])

Approach taken: Implement reduce(f) in PersistentVector.

Alternative: An alternate would be to change PersistentVector from IReduce to IReduceInit and remove the reduce without init function. In this case, reducing a vector would fall back to seqs.

Patch: 0001-CLJ-1619-Implement-no-init-arity-of-reduce-for-Persi.patch

Screened by: Stu

Activity

Hide
Alex Miller added a comment -

Is that return null there right? In the case of no elements, you should invoke f with no args right?

Show
Alex Miller added a comment - Is that return null there right? In the case of no elements, you should invoke f with no args right?
Hide
Nicola Mometto added a comment -

you're right, I didn't know that detail about the behaviour of reduce. Updated the patch to invoke (f) rather than returning nil when the coll is empty

Show
Nicola Mometto added a comment - you're right, I didn't know that detail about the behaviour of reduce. Updated the patch to invoke (f) rather than returning nil when the coll is empty
Hide
Alex Miller added a comment -

Needs tests

Show
Alex Miller added a comment - Needs tests
Hide
Nicola Mometto added a comment -

Updated patch adding testcases for PersistentVector.reduce in the already existing reduce test

Show
Nicola Mometto added a comment - Updated patch adding testcases for PersistentVector.reduce in the already existing reduce test
Hide
Stuart Halloway added a comment -

I don't understand the problem here. coll-reduce appears to cut off ever hitting this path (the tests call underlying interfaces directly).

  • Need a public API example showing the failure
  • Need tests covering main branches (i.e. the empty case)
Show
Stuart Halloway added a comment - I don't understand the problem here. coll-reduce appears to cut off ever hitting this path (the tests call underlying interfaces directly).
  • Need a public API example showing the failure
  • Need tests covering main branches (i.e. the empty case)
Hide
Stuart Halloway added a comment -

nevermind, screening 1572

Show
Stuart Halloway added a comment - nevermind, screening 1572

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: