collect

Collect/Gather the elements of r into a Container and return it.

TODO: Use std.container.util.make instead?: https://dlang.org/phobos/std_container_util.html#.make TODO: Rename container to output? TODO: Support Set-containers via insert aswell, or add alias put = insert to them? TODO: What about Appender? TODO: Rename from collect to gather.

Container
collect
(
Container
Range
)
(
Range r
)

Examples

import std.range : iota;
import std.algorithm.iteration : map, filter;
import nxt.algorithm_ex : collect;

alias E = int;
alias V = E[];
immutable n = 1000;

auto x = 0.iota(n).collect!V;

assert([0, 1, 2].map!(_ => _^^2).collect!V.equal([0, 1, 4]));
assert([0, 1, 2, 3].filter!(_ => _ & 1).collect!V.equal([1, 3]));

Meta