So I have a map like this: {"2018-05-22" {:A {123 "foo"}}}
. I need to transform "foo"
, but I need to collect some of the map keys (`"2018-05-22"` and :A
) along the way for the transformation function and I can't quite figure out how to do it.
@flowthing How do you need to navigate to "foo"? Recursively?
With MAP-VALS
. Basically, I'm doing something like this:
(specter/transform [specter/MAP-VALS specter/MAP-VALS specter/MAP-VALS] (fn [& args] ,,,) {"2018-05-22" {:A {123 "foo"}}})
And I'm wondering whether I can write the path such that the transformation fn gets "2018-05-22"
and :A
as arguments (in addition to "foo"
).@flowthing yes, you want to make use of collection navigators
(def MAP-VALS+ (path ALL (collect-one FIRST) LAST))
(transform [MAP-VALS+ MAP-VALS+ MAP-VALS]
(fn [k1 k2 v]
[k1 k2 v]
)
{"2018-05-22" {:A {123 "foo"}}})
Perfect, thank you!
I couldn't figure out how to compose MAP-VALS+
myself.