What is fundamental difference for having a '?' in every?
and not in some
functions of clojure?
user> (every? true? [true true false])
false
user> (some true? [true false false])
true
Thanks.
every?
returns true or false, so it gets a question mark. some
doesn't return a boolean, it returns "the first logically true value returned by pred", and returns nil
otherwise.
Here's the lame example I came up with:
user=> (some #(if (= 0 %) 1 0) [1 3 5 0 9])
0
The first element in the collection gets passed into the predicate, the predicate evaluates to 0, which is logically true so some
returns 0. you can see some
is not returning true or false.
So every?
gets a question mark because it returns true or false.
some
returns the value returned by pred
or nil, so it doesn't get a question mark.
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