countAmong

Array-specialization of countAmong with default predicate.

  1. ptrdiff_t countAmong(T[] haystack, T[][] needles)
    @trusted
    ptrdiff_t
    countAmong
    (
    T
    )
    (
    scope const T[] haystack
    ,
    scope const T[][] needles
    )
  2. ptrdiff_t countAmong(T[] haystack, T[] needles)
  3. bool startsWith(T[] haystack, T[] needle)
  4. bool startsWith(T[] haystack, T needle)

Examples

assert("".countAmong(string[].init) == -1);
assert("".countAmong([""]) == 1);
assert("".countAmong(["_"]) == 0);
assert("".countAmong([" "]) == 0);
assert(" ".countAmong([" "]) == 1);
assert("abc_abc".countAmong(["a"]) == 2);
assert("abc_abc".countAmong(["abc"]) == 2);
assert("_a_a_".countAmong(["_"]) == 3);
assert("_aaa_".countAmong(["a"]) == 3);
assert("".countAmong(string.init) == -1); // -1 instead of `assert` that `std.algorithm.count` does
assert("".countAmong("") == -1); // -1 instead of `assert` that `std.algorithm.count` does
assert(" ".countAmong("") == -1); // -1 instead of `assert` that `std.algorithm.count` does
assert("".countAmong("_") == 0);
assert("".countAmong(" ") == 0);
assert(" ".countAmong(" ") == 1);
assert("abc_abc".countAmong("a") == 2);
assert("abc_abc".countAmong(" ") == 0);
assert("abc_abc".countAmong("ab") == 4);
assert("abc_abc".countAmong("abc") == 6);
assert("_a_a_".countAmong("_") == 3);
assert("_aaa_".countAmong("a") == 3);

Meta