data.deque
data.deque copied to clipboard
Conj'ing a deque onto a set causes ClassCastException
(require '[data.deque :as dq])
(conj [] (dq/deque 1))
;;=> [<top-(1)-bottom>]
(conj #{} (dq/deque 1))
;;=> Unhandled java.lang.ClassCastException
;; data.deque.PersistentDeque cannot be cast to java.lang.Iterable
core.clj: 5186 clojure.core/hash-ordered-coll
core.clj: -1 clojure.core/hash-ordered-coll
deque.clj: 77 data.deque.PersistentDeque/hasheq
Util.java: 177 clojure.lang.Util/dohasheq
Util.java: 168 clojure.lang.Util/hasheq
PersistentHashMap.java: 120 clojure.lang.PersistentHashMap/hash
PersistentHashMap.java: 143 clojure.lang.PersistentHashMap/assoc
PersistentHashSet.java: 99 clojure.lang.PersistentHashSet/cons
PersistentHashSet.java: 17 clojure.lang.PersistentHashSet/cons
RT.java: 673 clojure.lang.RT/conj
core.clj: 85 clojure.core/conj
core.clj: 82 clojure.core/conj
I encountered the issue also for type data.deque.PersistentDequeSeq, as I tried to extract the item using seq as a work-around.
I ended up using map to obtain a non-data.deque type so was wondering if this is intentional? Thanks!
(conj #{} (map identity (dq/deque 1)))
;;=> #{(1)}
I intended `PersistentDeque's can be ordered (like vectors do). Collections can be ordered if each collection provides its own hash. https://clojure.org/reference/data_structures#_clojure_collection_hashes
PersistentDeque's hash is computed using hash-ordered-coll, and it's a bug that it doesn't reify Iterable also.
I'll fix that.