View Problem

Test if a condition holds for all items of a list

Given a list, test if a certain logical condition (i.e. predicate) holds for all items of the list.
ExpandDiskEdit
cpp boost
template <typename InputIterator, typename Predicate>
bool match_all(InputIterator first, InputIterator last, Predicate pred)
{
return find_if(first, last, !pred(_1)) == last;
}
DiskEdit
fsharp fsharp
let rec IsAll predicate source =
let mutable acc = true
for e in source do
acc <- acc && (predicate e)
acc

Submit a new solution for java, cpp, csharp, or fsharp
There are 10 other solutions in additional languages (clojure, erlang, fantom, groovy ...)