tailrecursion / cljs-priority-map

PersistentPriorityMap for ClojureScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: compare on non-nil objects of different types

jacobemcken opened this issue · comments

I've been using a priority-map inside an atom and I'm updating like the following:

(swap! my-priority-map update-in ["some key"] merge m)

The problem is that depending on the amount of keys in m (it seems), the merge function will either return PersistentHashMap or a PersistentArrayMap

Is there anyway that I can make the priority-map "not care" or force it to be one or the other?

Hi! I don't think the behavior you're seeing is related at all to priority-map - the update-in turns into an assoc on the priority map with the effect that the value at key "some key" becomes (merge old-value m).

What you are witnessing is Clojure choosing map implementations, for performance reasons, based on size. PersistentHashMap and PersisentArrayMap are types you're seeing in the priority-map, not of it.

Does this clear things up?

Yes I'm aware that Clojure is choosing map implementations... though it took me a while to figure out what was actually happening 😄

The reason I've opened an "issue" is that if I where to update-in a hash-map, array-map or sorted-map I wouldn't bump into the error because they don't sort by value.
I think I have solved my problem by using priority-map-by where I provide my own sorting function which doesn't care about the map type inserted as a value into the priority-map.

Thanks for taking time to explain it.