This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-01-30
Channels
- # admin-announcements (1)
- # announcements (1)
- # babashka (8)
- # bristol-clojurians (1)
- # calva (36)
- # clojure (115)
- # clojure-europe (5)
- # clojure-italy (4)
- # clojure-nl (3)
- # clojure-norway (3)
- # clojure-uk (161)
- # clojuredesign-podcast (3)
- # clojurescript (71)
- # core-async (34)
- # cursive (26)
- # datomic (43)
- # docker (2)
- # emacs (24)
- # figwheel-main (1)
- # fulcro (36)
- # graalvm (7)
- # immutant (2)
- # jackdaw (1)
- # jobs (2)
- # leiningen (8)
- # luminus (5)
- # off-topic (29)
- # onyx (1)
- # other-languages (5)
- # pathom (6)
- # pedestal (3)
- # reagent (11)
- # ring (8)
- # shadow-cljs (42)
- # spacemacs (17)
- # specter (6)
- # tools-deps (80)
- # videos (1)
is this an okay place to ask for help with an example? i have a simple tree, and i would like to collect a value from each parent and combine it with a value on its direct descendants. for example:
(def tree {:id 1
:value "one"
:children [{:id 2
:value "two"}
{:id 3
:value "three"
:children [{:id 4
:value "four"}]}]})
where after a transformation, each child gets a :parent+myvalue
key which is equal to (str (:value parent) (:value self))
(s/transform [...path] xfn tree)
{:id 1
:value "one"
:children [{:id 2
:value "two"
:parent+myvalue "onetwo"}
{:id 3
:value "three"
:parent+myvalue "onethree"
:children [{:id 4
:value "four"
:parent+myvalue "threefour"}]}]}
is Specter well suited for this, or should i just use core walk functions?@joshkh this is the kind of stuff specter is very good at
(def CHILDREN (path (must :children) ALL))
(def VALUE+CHILDREN (path (collect-one :value) CHILDREN))
(def WALKER
(recursive-path [] p
(continue-then-stay
DISPENSE
VALUE+CHILDREN
)))
(transform [VALUE+CHILDREN WALKER (collect-one :value) :parent+myvalue]
(fn [parent-value my-value _]
(str parent-value my-value))
tree)
that's one way to solve it