This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-06-07
Channels
- # aleph (5)
- # announcements (2)
- # babashka (17)
- # beginners (13)
- # cider (4)
- # clj-kondo (9)
- # cljdoc (18)
- # clojure (20)
- # clojure-art (7)
- # clojure-dev (11)
- # clojure-europe (20)
- # clojure-nl (2)
- # clojure-norway (53)
- # clojure-spec (30)
- # clojure-uk (4)
- # clojurescript (40)
- # datomic (70)
- # events (2)
- # graalvm-mobile (8)
- # gratitude (2)
- # guix (2)
- # honeysql (3)
- # hyperfiddle (10)
- # introduce-yourself (4)
- # jobs (2)
- # lsp (6)
- # luminus (3)
- # malli (5)
- # polylith (35)
- # practicalli (6)
- # re-frame (3)
- # reagent (9)
- # releases (1)
- # remote-jobs (20)
- # ring-swagger (2)
- # shadow-cljs (12)
- # sql (18)
- # xtdb (7)
Are the State of Clojure survey results for this year posted somewhere or are they still being processed?
apologies, I have been swamped. I did actually do some more work on the writeup last week and this week, trying to get it done
it is one of things that is never quite the most important thing :)
I'm writing a custom IPersistentMap
that renames the key if it already exists in the map, like this
(assoc (my-custom-map)
:a 1
:b 2
:a 3
:a 4)
#_#_=> {:a 1 :b 2 :a-1 3 :a-2 4}
Does anyone know if there is a library that already does this?
If not, what would be a good descriptive name for this map?I did something similar to track changes for a map but without renaming:
custom type with parent
field, in case assoc
is about to overwrite some key new map is returned having original in the parent
.
It was called TrackingMap
> What would use-cases for such a map be?
(log/info "my-message" {:random :data} ex)
I wanna be able to merge :random :data
with (ex-data ex)
, and other sources (like Mapped Diagnostic Context
etc), without lost data or getting it too nested.
> I wanna be able to merge :random :data with (ex-data ex), and other sources Isn't that what namespaced keywords are for?
I would highly NOT recommend making such a map. It's completely unobvious and requires one's time to understand what's going on. Instead, write a function that takes a seq of pairs and builds such a map. It would be a trivial reduce closed over a set of keys. It would also save you several days from inventing and testing your "smart" stuff.
maybe something you could just nest the data?
(log/info "my-message" {:data {:random :data} :ex ex})
> Isn't that what namespaced keywords are for?
Yes, but from the log library side can't assume that everyone that creates an ex-info
will use qualified keys.
@U1WAUKQ3E OK, implemented a clash-free-merge
, using the @U45T93RA6 naming.
In fact, I hope that this is a single-usage function.
No no. You misunderstood. If you use namespaced keys when you make the ex-info, you won't have any collisions.
If you're making a library, ::kw
is especially useful for avoiding collisions. Especially if you use reverse domain convention in your namespace name.
a quick and dirty version:
(defn clash-free-map [pairs]
(loop [map-idx {}
map-acc {}
[[k v :as pair] & pairs] pairs]
(if pair
(if-let [idx (get map-idx k)]
(let [k-new
(-> k str (subs 1) (str "-") (str idx) keyword)]
(recur (update map-idx k (fnil inc 0))
(assoc map-acc k-new v)
pairs))
(recur (update map-idx k (fnil inc 0))
(assoc map-acc k v) pairs))
map-acc)))
samples
(clash-free-map [[:a 1] [:b 2]])
{:a 1, :b 2}
(clash-free-map [[:a 1] [:a 2]])
{:a 1, :a-1 2}