Fork me on GitHub
#specter
<
2017-05-11
>
wilkerlucio14:05:16

hello, I'm trying to figure if I can use specter for a situation I have here

wilkerlucio14:05:41

I have a map, and I would like to filter the map by some criteria on the values

wilkerlucio14:05:04

today my Clojure code is:

wilkerlucio14:05:37

(->> some-map
     (filter (fn [[k v]]
               (> v 10)))
     (into {}))

wilkerlucio14:05:54

is there a way to replace this with specter select and avoid having to convert the data types?

nathanmarz15:05:39

@wilkerlucio (transform [MAP-VALS #(> % 10)] some-map)

nathanmarz15:05:24

that will maintain the type of the map and also run about 10x faster

wilkerlucio15:05:49

@nathanmarz thanks, didn't even occur to me to use transform to filter, but seeing it makes total sense 🙂

wilkerlucio15:05:22

I think would be nice to have some filter example like this on README

nathanmarz15:05:28

sorry, meant to write this: (setval [MAP-VALS #(<= % 10)] NONE some-map)

nathanmarz15:05:38

sleepy today

wilkerlucio15:05:17

haha, I was just coming back to ask, thanks for the speedy catch 🙂

wilkerlucio15:05:12

@nathanmarz why we need to invert the predicate?

wilkerlucio15:05:34

ah, gotcha, it's not about filtering ther,e it's about removing

nathanmarz15:05:14

yea, that's right