I have a sequence of values. I want to know if any of them evaluates true.
(def input [nil nil nil 1 nil 1])
I want to do something like this:
(apply or input)
But I can't because or is a macro not a function. Similarly this won't work
(reduce or input)
I've written my own
(def orfn #(if %1 %1 %2))
And now this works
(reduce orfn input)
As does this slightly different approach, although it only tests for nil.
(not (every? nil? input))
What's the 'right' way to apply or or equivalent?
You can use some with identity to do this:
(some identity [nil nil nil 1 nil 1])
=> 1
some returns the first truthy value from applying a function to a sequence, so this works because 1 is a truthy value.
(some identity [nil nil nil nil 1 nil 1])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With