This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-07-04
Channels
- # architecture (35)
- # babashka (1)
- # beginners (60)
- # biff (6)
- # cider (21)
- # clerk (14)
- # clojure (10)
- # clojure-europe (42)
- # clojure-nl (1)
- # clojure-norway (15)
- # clojure-sweden (6)
- # clojure-uk (12)
- # clojurescript (19)
- # community-development (1)
- # data-science (2)
- # datalevin (1)
- # datomic (22)
- # gratitude (1)
- # honeysql (1)
- # hyperfiddle (8)
- # introduce-yourself (5)
- # leiningen (12)
- # lsp (18)
- # off-topic (20)
- # overtone (6)
- # pedestal (5)
- # specter (5)
- # sql (12)
- # xtdb (2)
Hello Clojurians, I got this simple snippet:
(type (reduce
#(assoc %1 %2 %2)
(array-map)
(range 32)))
;; => clojure.lang.PersistentHashMap
Why does it returns a hash map instead of an array map? I mean I understand that at some point (16 keys IIRC?) Clojure converts array maps to hash maps for performance reasons, but what can I do, if knowing all the performance costs, I want to keep the array map?array maps always upgrade on assoc at 8 key/value pairs (16 array entries), there is no way to stop that
@U044Y4Z2R8D out of interest, why do you want to keep the array map? Is it just for keeping order? If so, https://github.com/clj-commons/ordered https://github.com/frankiesardo/linked or https://github.com/quoll/tiara are worth a look
@UE1N3HAJH yes, just for keeping order. Honestly I can't think about any other use case. But the question were more on the language design level, because the snippet above can be a little confusing. I understand "whys" of this but I was just curious about others opinions on this. Thanks for the links to libs however