countIf

Performs a linear scan of haystack from [0 .. haystack.length$(RP), returning a count of the number of elements where pred returns true.

  1. size_t countIf(T[] haystack, Pred pred)
    size_t
    countIf
    (
    in T[] haystack
    ,
    Pred pred = Pred.init
    )
  2. size_t countIf(Buffer!(T) haystack, Pred pred)

Parameters

haystack T[]

The array to scan.

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 number of elements where pred returns true.

Examples

test!("==")(countIf("gbbbi", ( char c ) { return c == 'b'; }), 3);

Meta