Coming from other functional programming environments (e.g., Clojure) I've become accustomed to some functions that I haven't found equivalents for in Mathematica yet.
The two I reached for last night were every
and some
.
Every
would return True
if the provided predicate function is True
for every element in the list. (and False
otherwise)
Some
would return True
if the provided predicate function is True
for at least one of the elements in the list. (and False
otherwise)
Every[{2, 4, 6}, EvenQ]
(* would return True *)
Every[{2, 4, 5}, EvenQ]
(* would return False *)
Some[{2, 4, 6}, OddQ]
(* would return False *)
Some[{2, 4, 5}, OddQ]
(* would return True *)
Perhaps some version of these are built-in and I've failed to find them in the docs?
Or, can we get a once-and-for-all efficient and elegant implementation of these that we can all use?
Or, is such an implementation impossible? (I hope not :)
Kind thanks, as ever.
Apologies if this question has been asked before, I saw some similar things, but none of the existing questions satisfied me.
For example, the following three questions are related, but suffer variously from bad specification in the question and low quality answers: