A predicate to match the needle against the elements in the haystack.
The array to search.
The index of the last match of pred when evaluating all elements in haystack, or -1 if none were found.
import std.conv : to; { enum haystack = "haystack"; alias pred = (n) => (n == 'a'); enum index = haystack.countUntilLastMatchOf!pred; static assert((index == 5), index.to!string); } { enum haystack = "haystack"; alias pred = (n) => (n < 'a'); enum index = haystack.countUntilLastMatchOf!pred; static assert((index == -1), index.to!string); } { enum haystack = "haystack"; alias pred = (n) => (n == char.init); enum index = haystack.countUntilLastMatchOf!pred; static assert((index == -1), index.to!string); } { enum haystack = string.init; alias pred = (n) => (n == '\0'); enum index = haystack.countUntilLastMatchOf!pred; static assert((index == -1), index.to!string); } { import std.uni : toLower; enum haystack = "HAYSTACK"; alias pred = (n) => (n.toLower == 'a'); enum index = haystack.countUntilLastMatchOf!pred; static assert((index == 5), index.to!string); } { enum haystack = "haystack"; enum pred = "a == 'y'"; enum index = haystack.countUntilLastMatchOf!pred; static assert((index == 2), index.to!string); }
Finds the index of the last match of a predicate in a haystack. The predicate is evaluated against each element.
Overload that takes a predicate instead of a needle.