This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-07-29
Channels
- # aleph (45)
- # announcements (13)
- # aws (7)
- # beginners (113)
- # biff (5)
- # cider (15)
- # cljs-dev (1)
- # clojure (101)
- # clojure-europe (38)
- # clojure-madison (1)
- # clojure-norway (9)
- # clojure-uk (4)
- # cursive (7)
- # data-science (2)
- # datomic (6)
- # emacs (31)
- # events (2)
- # fulcro (10)
- # graphql (3)
- # gratitude (1)
- # hyperfiddle (11)
- # nrepl (4)
- # off-topic (110)
- # pathom (57)
- # portal (15)
- # random (1)
- # reitit (3)
- # releases (1)
- # squint (14)
- # xtdb (7)
Good morning
Morning!
It's hard to stay off the ☕ after weekend-warrior shenanigans
Morning
Good morning! ☕️
Morning!
I still see my (newer) colleagues occasionally doing
(or (= :a foo)
(= :b foo))
instead of
(#{:a :b} foo)
Do you think there are stronger arguments for doing it either way?
Sets as fns is second nature to me by now, and I love their succinctness.
Also for stuff like
(filter (comp #{:a} :some-field) coll)
I'm on team sets-as-fns and comp
with the argument being that it most closely reflects my intent
Me too. It's easier to add to the set than add expressions to an or
fn. It is also more mathematical.
I also like sets :) It's more concise, especially compared to (or (= ,,,) (= ,,,)) - Last time I wrote clojure with people who didn't have much clojure experience, I held a bit back on the idioms that I knew wouldn't be familiar. The or looks about how it would be in Javascript. I think it's fine to adapt coding style a bit to the prople one's working with - even if one solution is considered more idiomatic by experienced clojure programmers.
I also use sets, but I prefer naming the set and using an explicit get, e.g. (get valid-stuff x)

I've also done (valid-stuff? x) but stopped doing that after learning that predicates should explicitly return true/false (i.e. can't just be a set if you're a pedant like me).
I can go either way — sometimes it feels like it helps, sometimes it feels superfluous
I often add a (contains? ,,,), I find reading it a little easier. Might just be what I'm familiar with. I sometimes add a specific get for map lookup too.
For statically known sets, if the idiom repeats often enough, I usually write a macro that unrolls to an or of identity checks for up to quite a large number of keys
Improved performance. A sequence of pointers comparisons will beat a set lookup probably up until the bytecode gets too large
Explicit 'contains' or '(or (= ...' are an easier way into Clojure for beginners/passing-byers, completely agree.
Additionally, I love the set of set operations. Small and effective.
For statically known setsI have a macro in clj-kondo which creates a case expression out of this:
(one-of :foo [:foo :bar :baz])
it depends, benchmark and you will know, but usually (or (= ...)) is faster than set membership, which is why I often still use it if that's important
Case creates big ugly bytecode If the set is only keywords you can even use identical? Up to a ridiculous number of elements (or (identical? ...) ...) Will be faster and smaller than a case --- I also call that macro one-of 😄
Morning
Additionally, I love the set of set operations. Small and effective.