From what I understand about apply, it unpacks a list and turns the elements into arguments for a function.
I see that (apply + [1 2 3]) works as expected, i.e: it's equivalent to (+ 1 2 3).
Why then is (apply or [true false]) invalid? Isn't it equivalent to (or true false) ?
Because or
is a macro, not a normal function. You can get the same effect with (some identity [true false])
.
As an alternative to or you can use (some predicate coll).
clojure.core/some ([pred coll])
Returns the first logical true value of (pred x) for any x in coll, else nil. One common idiom is to use a set as pred, for example this will return :fred if :fred is in the sequence, otherwise nil: (some #{:fred} coll)
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