specter

Latest version: 1.1.3
flowthing 2018-05-22T12:48:35.000455Z

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.

nathanmarz 2018-05-22T14:18:52.000070Z

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

flowthing 2018-05-22T14:22:52.000816Z

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

nathanmarz 2018-05-22T14:25:51.000309Z

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

nathanmarz 2018-05-22T14:25:53.000347Z

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

flowthing 2018-05-22T14:37:01.000139Z

Perfect, thank you!

flowthing 2018-05-22T14:38:03.000334Z

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