Fork me on GitHub
#specter
<
2016-07-08
>
richiardiandrea14:07:51

Started using specter as well ;)

richiardiandrea16:07:35

so first question 😄 let's say I have a map indexed by a long, but i don't care about that, I want to navigate to the value

richiardiandrea16:07:16

the [sp/ALL sp/MAP-VALS ] path navigates all the keys first, then values

richiardiandrea16:07:38

I'd like to skip keys if possible...

nathanmarz16:07:52

easier to understand if you show the input/output you're looking for

richiardiandrea16:07:40

{:handles {"booma" {:business {:id 3, :name "", :twitter-handle "booma"}, :sente-uids ["e8a6a187-1e6b-41d1-aa93-d0912a290f49" "arsassa-1e6b-41d1-aa93-d0912a290f49"]}
           "my-handle" {:business {:id 5, :name "Business", :twitter-handle "my-handle"}, :sente-uids ["artart27-1e6b-41d1-aa93-d091arsasr49"]}}}

richiardiandrea16:07:20

I'd like to fetch the inner maps, skipping the string key

nathanmarz16:07:44

there's a lot of inner maps

nathanmarz16:07:04

so you want the maps that have :business key?

richiardiandrea16:07:11

you are right, skip to {:business .....}

nathanmarz16:07:50

(select [:handles MAP-VALS] data)

nathanmarz16:07:17

can also do (select [:handles ALL LAST] data) but the former is more efficient

richiardiandrea16:07:55

oh cool, yes it works, so I needed no ALL in my code above...

richiardiandrea16:07:02

I so like the fact that you can transform in one go all the things you need to...thanks a lot for the help and the lib

richiardiandrea16:07:19

don't want to take too much of your time as I can check the samples, but I saw that you can collect data while you descend the data structure, in my case it would be really handy to carry the {"booma" {...} "my-handle" {...}} map in the transform...is it feasible with collect?

nathanmarz16:07:40

(transform [:handles VAL MAP-VALS ] ...

nathanmarz16:07:54

VAL is same as (collect-one STAY)

richiardiandrea16:07:14

perfect that is exactly what I need 😉

richiardiandrea17:07:55

my first specter transformation 🙂

(defn deregister-uid [state uid]
  (->> state
       (spm/transform (sp/multi-path :uids
                                     [:handles sp/MAP-VALS :sente-uids]
                                     [:businesses sp/MAP-VALS :sente-uids])
                      #(cond
                         (map? %) (dissoc % uid)
                         (vector? %) (vec (remove #{uid} %))
                         :else %))))