The OpenD Programming Language

rcfilter

Implements the higher order filter and map function. The predicate and map functions are passed to mir.functional.naryFun, and can either accept a string, or any callable that can be executed via pred(element) and map(element).

  1. auto rcfilter(Range r)
    template rcfilter(alias pred = "a", alias map = "a")
    static if(__traits(isSame, naryFun!pred, pred) && __traits(isSame, naryFun!map, map))
    rcfilter
    (
    Range
    )
    (
    Range r
    )
    if (
    isIterable!Range &&
    (
    !isSlice!Range ||
    DimensionCount!Range == 1
    )
    )
  2. auto rcfilter(Slice!(Iterator, N, kind) slice)

Members

Functions

rcfilter
auto rcfilter(Range r)
auto rcfilter(Slice!(Iterator, N, kind) slice)

Parameters

pred

Filter function to apply to each element of range (optional)

map

Map function to apply to each element of range

Return Value

rcfilter!(pred)(range) returns a new RCArray containing only elements map(x) in range for which pred(x) returns true.

Examples

import mir.ndslice.topology: iota;

auto val = 3;
auto factor = 5;
// Filter iota 2x3 matrix below 3
assert(iota(2, 3).rcfilter!(a => a < val).moveToSlice.equal(val.iota));
// Filter and map below 3
assert(6.iota.rcfilter!(a => a < val, a => a * factor).moveToSlice.equal(val.iota * factor));

See Also

Meta