rcmap

Implements the homonym function (also known as transform) present in many languages of functional flavor. The call rmap!(fun)(slice) returns an RC array (1D) or RC slice (ND) of which elements are obtained by applying fun for all elements in slice. The original slices are not changed. Evaluation is done eagerly.

Note: transposed and pack can be used to specify dimensions.

  1. auto rcmap(Slice!(Iterator, N, kind) slice)
    template rcmap(fun...)
    @optmath
    static if(fun.length == 1)
    static if(__traits(isSame, naryFun!(fun[0]), fun[0]))
    @optmath
    rcmap
    (
    Iterator
    size_t N
    SliceKind kind
    )
    (
    Slice!(Iterator, N, kind) slice
    )
    if (
    fun.length
    )
  2. auto rcmap(T[] array)
  3. auto rcmap(T withAsSlice)
  4. auto rcmap(Range r)
  5. alias rcmap = .rcmap!(staticMap!(naryFun, fun))
  6. alias rcmap = .rcmap!(adjoin!fun)

Members

Aliases

f
alias f = fun[0]
Undocumented in source.
rcmap
alias rcmap = .rcmap!(adjoin!fun)
Undocumented in source.
rcmap
alias rcmap = .rcmap!(staticMap!(naryFun, fun))
Undocumented in source.

Functions

rcmap
auto rcmap(Slice!(Iterator, N, kind) slice)
auto rcmap(T[] array)
auto rcmap(T withAsSlice)
auto rcmap(Range r)

Parameters

fun

One or more functions.

Examples

Returns RCArray for input ranges and one-dimensional slices.

import mir.algorithm.iteration: filter, equal;
auto factor = 10;
auto step = 20;
assert (3.iota.rcmap!(a => a * factor).moveToSlice.equal(3.iota * factor)); 
assert (6.iota.filter!"a % 2".rcmap!(a => a * factor).moveToSlice.equal([3].iota(factor, step))); 

For multidimensional case returns Slice!(RCI!T, N).

import mir.ndslice.topology : iota;
auto factor = 3;
auto s = iota(2, 3).rcmap!(a => a * factor);
assert(s == iota(2, 3) * factor);

String lambdas

import mir.ndslice.topology : iota;
assert(iota(2, 3).rcmap!"a * 2" == iota(2, 3) * 2);

See Also

Meta