Clojure

clojure.core/bean should implement Iterable

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Patch:
    Code and Test
  • Approval:
    Triaged

Description

The changes in Clojure 1.6 hashing revealed that `bean` does not return a map that implements Iterable:

user=> (hash (bean (java.util.Date.)))

AbstractMethodError clojure.lang.APersistentMap.iterator()Ljava/util/Iterator;  clojure.core.proxy$clojure.lang.APersistentMap$ff19274a.iterator (:-1)

Patch adds `iterator` method to clojure.core/bean.

Activity

Hide
Ambrose Bonnaire-Sergeant added a comment -

Added new patch that just adds iterator to bean.

Show
Ambrose Bonnaire-Sergeant added a comment - Added new patch that just adds iterator to bean.
Hide
Ambrose Bonnaire-Sergeant added a comment -

It seemed like an oversight that APersistentMap lacked a default iterator method.

That said, I haven't used OO inheritance for 4 years. Should I change the patch?

Show
Ambrose Bonnaire-Sergeant added a comment - It seemed like an oversight that APersistentMap lacked a default iterator method. That said, I haven't used OO inheritance for 4 years. Should I change the patch?
Hide
Alex Miller added a comment - - edited

APersistentMap implements Iterable and expects subclasses to fulfill that contract. The bean proxy does not. Instead of changing APersistentMap, why not add:

(iterator [] (.iterator pmap)

to the bean proxy definition?

Show
Alex Miller added a comment - - edited APersistentMap implements Iterable and expects subclasses to fulfill that contract. The bean proxy does not. Instead of changing APersistentMap, why not add:
(iterator [] (.iterator pmap)
to the bean proxy definition?
Hide
Alex Miller added a comment -

One workaround:

(hash (apply hash-map (bean (java.util.Date.))))

Interestingly, into does not help b/c into uses reduce, which internally uses the iterator too.

Show
Alex Miller added a comment - One workaround:
(hash (apply hash-map (bean (java.util.Date.))))
Interestingly, into does not help b/c into uses reduce, which internally uses the iterator too.

People

Vote (2)
Watch (4)

Dates

  • Created:
    Updated: