Fork me on GitHub
#clojure
<
2022-06-25
>
Adam Helins07:06:00

(= false (sorted? (update-vals (sorted-map) identity))) Hmmm, this feels slightly controversial

Alex Miller (Clojure team)10:06:16

The doc string says “returns a new map”

Adam Helins10:06:32

Yes but intuitively I was expecting the new map to remain sorted

Adam Helins10:06:00

Not saying it definitely should but that was my expectation

andy.fingerhut15:06:08

From the implementation, looks like there was a preference to always achieving the performance of transients in update-vals, at the expense of returning a "vanilla map" if the input map does not implement transients, which several alternate kinds of maps do not.

Alex Miller (Clojure team)16:06:41

Yep, there were tradeoffs and we made our choice there as reflected in the docstring

Eric Dvorsak16:06:34

sorted-map isn't a clojure.lang.IEditableCollection?

andy.fingerhut21:06:49

No, as can be demonstrated quickly in a REPL:

Clojure 1.11.1
user=> (instance? clojure.lang.IEditableCollection {})
true
user=> (instance? clojure.lang.IEditableCollection (sorted-map))
false

andy.fingerhut21:06:30

It is of course possible to develop a modified version of the sorted-map implementation that implemented that interface. I do not know whether its performance advantages would be worth the development effort.