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. Elem[] filter(Elem[] array, Pred1E pred, Elem[] buf)
    version(TangoDoc)
    filter
    (,,
    Elem[] buf = null
    )
  2. template filter(Array, Pred)

Parameters

array Elem[]

The array to scan.

pred Pred1E

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 Elem[]

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

Return Value

Type: Elem[]

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.

Meta