Merge pull request #3954 from quickfur/canfind_docs

Add example of how to use a custom predicate with canFind.
This commit is contained in:
Jonathan M Davis 2016-02-02 04:38:40 -08:00
commit 747135d6d6

View file

@ -2207,6 +2207,21 @@ template canFind(alias pred="a == b")
assert(canFind([0, 1, 2, 3], [1, 3], [2, 4]) == 0);
}
/**
* Example using a custom predicate.
* Note that the needle appears as the second argument of the predicate.
*/
@safe unittest
{
auto words = [
"apple",
"beeswax",
"cardboard"
];
assert(!canFind(words, "bees"));
assert( canFind!((string a, string b) => a.startsWith(b))(words, "bees"));
}
@safe unittest
{
import std.algorithm.internal : rndstuff;