Fork me on GitHub
#specter
<
2021-09-04
>
oskarkv20:09:06

I want to filter a list based on nested values. Basically this

(filter
 #(and (= (get-in % [:a :b]) 1)
       (= (get-in % [:a :c]) 2))
 data)
Can specter help me here?

Joshua Suskalo20:09:11

It can help with performance here as it's faster than get-in

Joshua Suskalo20:09:10

If I were to write this in specter natively it would look like this:

(select [ALL (selected? (must :a :b) (pred= 1)) (selected? (must :a :c) (pred= 2))] data)

oskarkv21:09:54

Thanks! But this not just filters, it has mapped :a over the data too. Can I use selected? before the :a without having to repeat the :a for both conditions somehow?

Joshua Suskalo21:09:57

Ah, right, my mistake. Yes.

Joshua Suskalo21:09:43

I edited the example to be accurate.