View Problem

Test if a condition holds for any items of a list

Given a list, test if a certain logical condition (i.e. predicate) holds for any items of the list.
DiskEdit
ruby
[2, 3, 4].any? { |x| x > 3 }
DiskEdit
clojure
; The standard library in Clojure has "not-any?" but (oddly enough) no "any?"
(defn any? [pred coll]
((complement not-any?) pred coll))

(any? #(> % 3) [2 3 4])
DiskEdit
clojure
(some #(> % 3) [2 3 4])
ExpandDiskEdit
cpp boost
template <typename InputIterator, typename Predicate>
bool match_any(InputIterator first, InputIterator last, Predicate pred)
{
return find_if(first, last, pred) != last;
}
DiskEdit
erlang
Result = lists:any(Pred, List).

Submit a new solution for ruby, clojure, cpp, or erlang
There are 8 other solutions in additional languages (fantom, fsharp, groovy, haskell ...)