map

Apply a function to each element an array. The function's return values are stored in another array.

  1. U[] map(T[] array, MapFunc func, Buffer!(U) buf)
    U[]
    map
    (
    T
    U
    MapFunc
    )
    (
    in T[] array
    ,
    MapFunc func
    ,
    ref Buffer!(U) buf
    )
  2. U[] map(T[] array, MapFunc func, U[] pseudo_buff)

Parameters

array T[]

the array.

func MapFunc

the function to apply.

buf Buffer!(U)

a buffer in which to store the results. This will be resized if it does not have sufficient space.

Return Value

Type: U[]

an array (the same as the buffer passed in, if possible) where the ith element is the result of applying func to the ith element of the input array

Examples

Buffer!(long) buffer;
auto mapping = map(
    [1, 17, 8, 12][],
    (int i) { return i * 2L; },
    buffer
);
test!("==")(mapping[], [2L, 34L, 16L, 24L]);

Meta