This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-04
Channels
- # aleph (1)
- # announcements (7)
- # beginners (22)
- # calva (31)
- # cider (2)
- # clj-commons (1)
- # clj-http (2)
- # clj-kondo (10)
- # cljsrn (33)
- # clojure (18)
- # clojure-europe (7)
- # clojure-nl (3)
- # clojure-uk (2)
- # clojurescript (93)
- # depstar (3)
- # events (1)
- # figwheel-main (3)
- # fulcro (13)
- # graalvm (95)
- # graphql (1)
- # introduce-yourself (1)
- # lsp (92)
- # off-topic (2)
- # pathom (11)
- # releases (1)
- # shadow-cljs (33)
- # specter (6)
- # tools-deps (4)
- # vim (3)
- # web-security (1)
- # xtdb (7)
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?It can help with performance here as it's faster than get-in
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)
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?
Ah, right, my mistake. Yes.
I edited the example to be accurate.