Fork me on GitHub
#specter
<
2016-10-07
>
nathanmarz00:10:12

@nlessa what do you mean by "most profound"?

nlessa14:10:33

hi @nathanmarz. I mean: navigating continuously in the hierarchy by the :c key, get the last :c you navigated and the get the value of :a 3 examples:

{:a 1 :b: 1 :c {:a 2 :d 2 :c {:a 3 :b 3 :c  {:a 4 :h 4}}}} =>   4

   {:a 1 :b 1 :c: {:a 2 :d 2 :f {:a 3 :b 3 :c  {:a 4 :h 4} }}}} =>  2

   {:a 1 :b: 1 :j {:a 2 :d 2 :c {:a 3 :b 3 :c  {:a 4 :h 4}}}} =>  1
Is it clear?

nathanmarz14:10:46

@nlessa you can do something like this with 0.12.0

(declarepath LastCMap)
(providepath LastCMap
  (if-path (must :c)
    [:c LastCMap]
    STAY
    ))

(select-any [LastCMap :a] data)

nathanmarz14:10:00

though I really recommend using 0.13.0, which is much better at things like this

nathanmarz14:10:31

in 0.13.0 you can do it like this:

(def LastMap
  (recursive-path [k] p
    (if-path (must k)
      [(keypath k) p]
      STAY)))

(select-any [(LastMap :c) :a] data)

nlessa15:10:10

Thank you very much, @nathanmarz. Specter is really great, very elegant! When we see the solution it seems obvious. 🙂 I am yet struggling to dominate all the navigators logic and solve some problems in the specter-way.

nathanmarz15:10:02

you'll get there, it just takes practice

nathanmarz15:10:16

and a certain amount of retraining on how you think about data structures

aaelony18:10:38

is a transformation from [[:a :b] [:a :c] [:b :d] [:c :d]] to {:a [:b :c], :b [:d], :c [:d]} something that Specter is designed for? Not sure if that should be a transform or a setval or something else...

nathanmarz18:10:01

@aaelony the target object doesn't really share any structure with the source, so I would just do that with regular clojure functions