Fork me on GitHub

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?


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


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


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.


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?


not sure what you mean by that


do you have a representative example?


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


@razum2um no, that's pretty idiomatic

👌 4