findIf

Performs a linear scan of haystack from [0 .. haystack.length$(RP), returning the index of the first element where pred returns true.

  1. size_t findIf(T[] haystack, Pred pred)
  2. size_t findIf(Buffer!(T) haystack, Pred pred)
    size_t
    findIf
    (
    T
    Pred
    )
    (,
    Pred pred
    )

Parameters

haystack Buffer!(T)

The array to search.

pred Pred

The evaluation predicate, which should return true if the element is a valid match and false if not. This predicate may be any callable type.

Return Value

Type: size_t

The index of the first match or haystack.length if no match was found.

Examples

auto buffer = createBuffer("bcecg");
test!("==")(findIf(buffer, ( char c ) { return c == 'a'; }), 5);
test!("==")(findIf("bcecg", ( char c ) { return c == 'a'; }), 5);

Meta