Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: compare on non-nil objects of different types #6

Closed
jacobemcken opened this issue Aug 25, 2014 · 2 comments
Closed

Error: compare on non-nil objects of different types #6

jacobemcken opened this issue Aug 25, 2014 · 2 comments

Comments

@jacobemcken
Copy link

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?

@alandipert
Copy link
Member

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?

@jacobemcken
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants