Fork me on GitHub
#beginners
<
2023-07-30
>
itaied08:07:07

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)

pyry08:07:44

Those will work and are quite clear to me.

2
pyry08:07:16

You could argue that using eg. a set as a predicate might be more idiomatic.

👍 2
carnundotcom08:07:51

(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

pyry08:07:08

Clojure 1.11.1
user=> (#{:a :b} :a)
:a
user=> (#{:a :b} :c)
nil
user=> (if (#{:a :b} :a) "included" "not included")
"included"

itaied08:07:53

yes i only care about "truthy"

itaied08:07:04

thanks i like the set as a function idiom

👍 4
itaied08:07:19

consistent with the rest of the app map key as a function

Reut Sharabani08:07:00

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.

carnundotcom08:07:49

Yeah it's really nice. E.g. see docstring of some. https://clojuredocs.org/clojure.core/some

itaied08:07:55

oh I see.. seems like contains? overcome this though

carnundotcom08:07:38

Same problem I would think.

Benjamin18:07:10

how do I install clj tools-deps on alpine? 😅 ok I do this https://gist.github.com/aviflax/5d5e417d6bbdd8a1f1c8cbc9cbc348fc

hiredman19:07:17

Use clojure not clj

Benjamin19:07:59

what is -P ?