This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-06-25
Channels
- # babashka (31)
- # beginners (38)
- # biff (1)
- # calva (10)
- # clj-kondo (10)
- # clj-otel (9)
- # clojure (9)
- # clojure-europe (4)
- # clojure-norway (4)
- # clojurescript (26)
- # cursive (2)
- # datahike (3)
- # datomic (4)
- # emacs (6)
- # inf-clojure (2)
- # missionary (11)
- # nbb (3)
- # off-topic (9)
- # portal (17)
- # re-frame (16)
- # reagent (1)
- # releases (3)
- # shadow-cljs (5)
- # tools-build (17)
- # tools-deps (2)
- # xtdb (6)
(= false (sorted? (update-vals (sorted-map) identity)))
Hmmm, this feels slightly controversial
The doc string says “returns a new map”
Yes but intuitively I was expecting the new map to remain sorted
Not saying it definitely should but that was my expectation
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.
Yep, there were tradeoffs and we made our choice there as reflected in the docstring
sorted-map isn't a clojure.lang.IEditableCollection?
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
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.