Fork me on GitHub
#specter
<
2016-03-15
>
alexisgallagher21:03:39

I have a basic specter question. I think I'm just not understanding its fundamental concepts.

alexisgallagher21:03:44

Say I have a vector mymaps like so:

alexisgallagher21:03:02

(def mymaps [{:a 1 :b 2 :c {:d true}}
               {:a 2 :b 2 :c {:d false}}
               {:a 3 :b 2 :c {:d true}}])

alexisgallagher21:03:47

And I want to select all the items where the nested map's :d's value is true. If I was using filter and get-in, I'd just do it like so:

alexisgallagher21:03:58

(filter #(get-in % [:c :d]) mymaps)

alexisgallagher21:03:15

How would I do this with specter?

alexisgallagher21:03:48

I'm supposing I should use the select operator, since I don't want to transform components of the original structure in place. I only want to select certain components within it.

alexisgallagher21:03:24

So, trivially, I could use select to pull out all the boolean values I want to test, by doing:

alexisgallagher21:03:28

(select [ALL :c :d] mymaps)

alexisgallagher21:03:36

But this just gives me an array of booleans.

alexisgallagher21:03:56

If I want to use those values as a predicate to select the maps themselves, then ... ?