filter

Performs a linear scan of buf from [0 .. buf.length$(RP), creating a new array with just the elements that satisfy pred. The relative order of elements will be preserved.

  1. T[] filter(T[] array, Pred pred, Buffer!(T) buf)
    T[]
    filter
    (
    T
    Pred
    )
    (
    in T[] array
    ,
    Pred pred
    ,
    ref Buffer!(T) buf
    )
  2. T[] filter(T[] array, Pred pred, T[] pseudo_buf)

Parameters

array T[]

The array to scan.

pred Pred

The evaluation predicate, which should return true if the element satisfies the condition and false if not. This predicate may be any callable type.

buf Buffer!(T)

an optional buffer into which elements are filtered. This is the array that gets returned to you.

Return Value

Type: T[]

A new array with just the elements from buf that satisfy pred.

Notes: While most Array functions that take an output buffer size that buffer optimally, in this case, there is no way of knowing whether the output will be empty or the entire input array. If you have special knowledge in this regard, preallocating the output buffer will be advantageous.

Examples

Buffer!(char) result;
test!("==")(filter("aabbaab",
    (char c) { return c == 'a'; }, result), "aaaa");

Meta