mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 22:50:38 +03:00
Add all to std.algorithm and alias canFind to any for consistency with standard functional programming terminology.
This commit is contained in:
parent
49e4bb0ef0
commit
d1938e5563
1 changed files with 28 additions and 0 deletions
|
@ -7790,6 +7790,34 @@ if (is(typeof(find!pred(range))))
|
|||
return !find!pred(range).empty;
|
||||
}
|
||||
|
||||
/**
|
||||
Alias for canFind, for consistency with terminology typically used in
|
||||
functional languages.
|
||||
*/
|
||||
alias canFind any;
|
||||
|
||||
/**
|
||||
Returns $(D true) if and only if all values in $(D range) satisfy the
|
||||
predicate $(D pred). Performs $(BIGOH r.length) evaluations of $(D pred).
|
||||
|
||||
Examples:
|
||||
---
|
||||
assert(all!"a & 1"([1, 3, 5, 7, 9]));
|
||||
assert(!all!"a & 1"([1, 2, 3, 5, 7, 9]));
|
||||
---
|
||||
*/
|
||||
bool all(alias pred, R)(R range)
|
||||
if(isInputRange!R && is(typeof(unaryFun!pred(range.front))))
|
||||
{
|
||||
return find!(not!(unaryFun!pred))(range).empty;
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
assert(all!"a & 1"([1, 3, 5, 7, 9]));
|
||||
assert(!all!"a & 1"([1, 2, 3, 5, 7, 9]));
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
debug(std_algorithm) scope(success)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue