Best way to test predicate against a range

BCS none at anon.com
Sat Jun 26 23:07:27 PDT 2010


Hello Jonathan,

> For example, there are two functions that I'd like to be have: all()
> and any(). That is, I want a function which checks a predicate against
> a range and returns whether all elements in that range satisfy the
> predicate, and I want a function that checks a predicate against a
> range and returns whether any element satisfies the predicate.
> Ideally, all() would shortcut if it found even one element which
> didn't satisfy the predicate, and any() would shortcut if it found
> even one that did.

The trivial solution (no shortcuting) would be to map the predicate and reduce 
via 'and' or 'or'.

-- 
... <IXOYE><





More information about the Digitalmars-d-learn mailing list