specter

oskarkv 2021-09-04T20:10:06.005600Z

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?

2021-09-04T20:48:11.006100Z

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

2021-09-04T20:57:10.009500Z

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)

oskarkv 2021-09-04T21:15:54.009600Z

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?

2021-09-04T21:52:57.009900Z

Ah, right, my mistake. Yes.

2021-09-04T21:53:43.010200Z

I edited the example to be accurate.