This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-10-06
Channels
- # babashka (19)
- # beginners (68)
- # calva (9)
- # cider (27)
- # clj-kondo (64)
- # clj-on-windows (2)
- # cljdoc (8)
- # clojure (11)
- # clojure-europe (58)
- # clojure-italy (1)
- # clojure-nl (23)
- # clojure-uk (5)
- # clojurescript (9)
- # cryogen (18)
- # cursive (14)
- # data-science (17)
- # emacs (6)
- # gorilla (6)
- # graphql (1)
- # gratitude (2)
- # holy-lambda (10)
- # introduce-yourself (1)
- # jackdaw (3)
- # jobs (1)
- # leiningen (2)
- # malli (3)
- # missionary (33)
- # off-topic (21)
- # pedestal (7)
- # polylith (8)
- # quil (3)
- # random (1)
- # releases (1)
- # remote-jobs (7)
- # shadow-cljs (18)
- # specter (1)
- # sql (8)
I have a strange question that might not make sense, but does cljs have a way to check whether two given immutable values share the same “parent” in its structural sharing “chain”?
(def m {:a 1})
(common-parent? m (assoc m :b 1))
;; => true
I realize this is a really weird ask, and probably not something I should be doing 😅although you could use metadata to track this (def m ^{:foo 1} {:a 1})
(meta (assoc m :b 1))
. as long as you use assoc/dissoc/update and stuff the metadata will remain
Yea that’s interesting. Maybe store some kind of generated id in the metadata for comparison later:
(def m ^{:id (str (gensym))} ...)
It seems like metadata can probably help you. Just watch out for all the gotchas in the cases where metadata can disappear.
Yea definitely. Basically sticking to core functions and never accidentally recreating values from scratch? I’ve noticed in UI dev, even without metadata involved, I tend to think about the lifetimes of my values to ensure that prop diff checking remains very fast. I imagine metadata survival is a similar problem.