defcache needs to impl. iterator() to avoid Clojure 1.7 breakage
After upgrading to Clojure 1.7 beta2 some of our code started failing, specifically attempts to use iterator() on (keys our-cache).
This is because post http://dev.clojure.org/jira/browse/CLJ-1499, calls to iterator on Seqables optimize by delegating to underlying collection iterator. defcache implements IPersistentMap but not iterator therefore:
Proposal: Make defcache implement Iterable (which is implied by implementing IPersistentMap). I implemented by invoking .iterator on the underlying base-field, however this brings up the issue of reflection (warnings then popped up). To fix, I applied meta to base-field to type-hint it to clojure.lang.IPersistentMap.
This seems implied by various checks for map? elsewhere but I am not certain this is the correct type hint. It could be as narrow as java.lang.Iterable to be sufficient, but it seemed better to make a broader statement here if that is correct.
Patch applied for next release.
Looks like a winner to me.
Is there any fix planned?
or should core.cache be considered permanently broken for clojure 1.7 ?
The relevant ticket is not CLJ-1499 but CLJ-1602.
defcache creates a deftype that implements IPersistentMap, but does not implement Iterable/iterator, even though IPersistentMap extends Iterable, so I consider this broken.