How can I apply "or" in Clojure?

I have a sequence of values. I want to know if any of them value the truth.

(def input [nil nil nil 1 nil 1])

I want to do something like this:

(apply or input)

But I can not, because it or is a macro , not a function. Similarly, it will not work

(reduce or input)

I wrote my own

(def orfn #(if %1 %1 %2))

And now it works

(reduce orfn input)

How this is a little different, although he only checks for nil.

(not (every? nil? input))

What is the “right” way apply oror equivalent?

+4
source share
2 answers

You can use somewith help identityfor this:

(some identity [nil nil nil 1 nil 1])
=> 1

some , , 1 .

+9

(some identity [nil nil nil nil 1 nil 1])

+4

All Articles