Fork me on GitHub
#specter
<
2017-03-09
>
chromalchemy23:03:08

I am trying to filter a map, but return a map, not just the filtered values. I can use setval, but how do I go one level deep? {:id1 {:a false} :id2 {:a true}} -> {:id2 {:a true}} using something like (setval [MAP-VALS :a true?] ....)

nathanmarz23:03:07

@chromalchemy I think you're looking for:

(setval [MAP-VALS (selected? :a (complement identity))] NONE data)

chromalchemy23:03:51

Perfect Thanks!!! Trying to understand (selected?). What is the difference between [ALL even?] and [ALL (selected? even?)]?

nathanmarz23:03:39

those particular examples are equivalent

nathanmarz23:03:56

selected? in general is a filter on whether the path selects anything

nathanmarz23:03:19

if you only give it functions it's the same as just using those functions directly in the path

chromalchemy23:03:51

Ok so if the path does not "select" a thing, then it is effectively filtered out of the result.

chromalchemy23:03:59

Thank you again for Specter and the recent push to 1.0!!! I was surprised to read the consternated feedback on reddit. As a relative noob, it is for me much more obvious and empowering than than the walls I regularly run into when trying to juggle basic clojure functions to screen and transform data for UI stuff in cljs.

chromalchemy23:03:22

Still a bit confused why

(setval
      [MAP-VALS (selected? :a true?)]
      NONE
      {:id1 {:a false} :id2 {:a true}})
returns {:id1 {:a false}} But i'm up an running nonetheless simple_smile

chromalchemy23:03:51

I guess NONE gets rid of the maps that pass the true? test.

nathanmarz23:03:56

that code is selecting which values to remove (as opposed to which values to keep)

chromalchemy23:03:02

Ok , got it. Thx for the clarification.