var.byElement

ElementRange byElement() @safe

Get a forward range over the elements of this array.

This method returns an ElementRange that can be used with std.algorithm functions and other range-based operations.

Returns

An ElementRange over the array elements, or an empty range if this is not an array.

Examples

import std.algorithm : filter, map;
import std.array : array;
var arr = var([1, 2, 3, 4, 5]);
auto evens = arr.byElement.filter!(e => e.as!int % 2 == 0).map!(e => e.as!int).array;
assert(evens == [2, 4]);
ConstElementRange byElement() const @safe

Const overload: get a forward range over the elements of this array.

This method returns a ConstElementRange that can be used with std.algorithm functions and other range-based operations on const var arrays.

Returns

A ConstElementRange over the array elements, or an empty range if this is not an array.