specter

Latest version: 1.1.3
alexisvincent 2018-07-27T17:34:47.000253Z

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?

alexisvincent 2018-07-27T17:38:22.000261Z

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

nathanmarz 2018-07-27T17:57:50.000338Z

@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})

alexisvincent 2018-07-27T17:59:08.000424Z

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.

alexisvincent 2018-07-27T18:02:00.000156Z

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?

nathanmarz 2018-07-27T18:09:44.000150Z

not sure what you mean by that

nathanmarz 2018-07-27T18:09:51.000181Z

do you have a representative example?

razum2um 2018-07-27T21:34:18.000071Z

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)?

nathanmarz 2018-07-27T21:53:58.000163Z

@razum2um no, that's pretty idiomatic

1šŸ‘Œ