Function compactBy

Compacts a range by a publicly visible member variable or property of ElemntType!Range

auto auto compactBy(string member, alias pred, Range) (
  Range range
)
if (from.std.range.isInputRange!Range);

Parameters

NameDescription
member which member in ElementType!Range to compact by
pred a unary predicate that returns true if value should be compacted
range an input range

Returns

compacted range

Since

0.0.1

Example

import ddash.utils: isFalsey;
struct A {
    int x;
    private int y;
}
assert([A(3, 2), A(0, 1)].compactBy!("x", isFalsey).equal([A(3, 2)]));
assert(!__traits(compiles, [A(3, 2)].compactBy!("y", isFalsey)));
assert(!__traits(compiles, [A(3, 2)].compactBy!("z", isFalsey)));
assert(!__traits(compiles, [A(3, 2)].compactBy!("", isFalsey)));