Fork me on GitHub
#specter
<
2016-05-20
>
seantempesta01:05:36

hey everyone. Just started using specter and I’m clearly missing something. Why does this return nil?

(s/select [:groups s/ALL (s/keypath 15)] {:groups {:present {15 "hi"}}})

wei07:05:43

how would you write this in specter- given a range of numbers, increment the even numbers and remove the odd numbers? i.e. (transform [..] (fn [n] ..) (range 10)) => (1 3 5 7 9) this is a contrived example, but basically I’m transforming the value in one case and removing from the list in another case

tcoupland10:05:41

@seantempesta: s/ALL creates a sequence of everything refered to by :groups, [[:present {15 "hi"}]] here, so you need to decend another level of the structure. Either with :present or s/LAST would do the trick

nathanmarz14:05:43

@wei You can do it with a navigator like this:

(defpath ALL-ELEM-SEQ []
  (select* [this structure next-fn]
    (mapcat (fn [e] (next-fn [e])) structure)
    )
  (transform* [this structure next-fn]
    (mapcat (fn [e] (next-fn [e])) structure)    
    ))

nathanmarz14:05:21

(transform [... ALL-ELEM-SEQ] (fn [[v]] (if (even? v) [(inc v)])))