Fork me on GitHub
#specter
<
2018-05-22
>
flowthing12:05:35

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.

nathanmarz14:05:52

@flowthing How do you need to navigate to "foo"? Recursively?

flowthing14:05:52

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").

nathanmarz14:05:51

@flowthing yes, you want to make use of collection navigators

nathanmarz14:05:53

(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"}}})

flowthing14:05:01

Perfect, thank you!

flowthing14:05:03

I couldn't figure out how to compose MAP-VALS+ myself.