This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
what's the clojure of returning true if a variable equals to any of the given values?
(or (= axis :rows) (= axis :columns))
(contains? #{:rows :columns} axis)
(boolean (#{:rows :columns} axis))
I suppose. Though boolean
is unnecessary if you only care about truthy (or nil), not strictly true (or false).
See https://blog.jdriven.com/2020/06/clojure-goodness-using-sets-as-functions/#:~:text=A%20set%20in%20Clojure%20is,for%20example%20in%20collection%20functions
Clojure 1.11.1
user=> (#{:a :b} :a)
:a
user=> (#{:a :b} :c)
nil
user=> (if (#{:a :b} :a) "included" "not included")
"included"
imo contains?
is clearer because it describes what you're doing without relying on the weird fact that a set is a function.
otoh contains?
is confusing with other collections.
Yeah it's really nice. E.g. see docstring of some
.
https://clojuredocs.org/clojure.core/some
One little 'gotcha' though: https://clojuredocs.org/clojure.core/some#example-54b80c5ce4b0e2ac61831cb9
Same problem I would think.
how do I install clj
tools-deps on alpine? 😅 ok I do this https://gist.github.com/aviflax/5d5e417d6bbdd8a1f1c8cbc9cbc348fc