Fork me on GitHub
#specter
<
2018-07-27
>
alexisvincent17:07:47

Hi there, was wondering if you have a way of selecting a submap with a predicate on map keys or value. Perhaps something like the reverse of ALL for map entries?

alexisvincent17:07:22

For example

(select [ALL (comp even? second)] {:a 1 :b 2 :c 3})
in this case to get back the submap {:b 2} rather then the list of entries. But as a path, so that it can be composed

nathanmarz17:07:50

@alexisvincent one common way to do that would be to do the inverse using setval, e.g. (setval [MAP-VALS odd?] NONE {:a 1 :b 2 :c 3})

alexisvincent17:07:08

Thanks Nathan! But what I’m really trying to achieve is to construct a path, that I can compose to access deeper things in the map.

alexisvincent18:07:00

Is it possible for instance to make a navigator that takes a list of entries and transforms it to a map, such that it still works with the reconstruction process?

nathanmarz18:07:44

not sure what you mean by that

nathanmarz18:07:51

do you have a representative example?

razum2um21:07:18

Hi, I started using collect but find it a bit awkward, passing 2 args into modify-fn:

(def data {18 [{:rate 30} {:rate 15}], 50 [{:rate 35}]})
(transform [MAP-VALS (collect ALL :rate)] (fn [xs _] (average xs)) data) ;; ok
(transform [MAP-VALS (collect ALL :rate)] average data)
ArityException Wrong number of args (2) passed to: user/average
is there a more concise version of 2nd line (dont want to change average arity only for specter)?

nathanmarz21:07:58

@razum2um no, that's pretty idiomatic

👌 4