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?i suspect s/collect
comes into play
@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
aha, thanks for the working example. i always come back to specter after just long enough away to forget its paradigms 🙂