var.byPair

PairRange byPair() @safe

Get a forward range over the key-value pairs of this object.

This method returns a PairRange that can be used with std.algorithm functions and other range-based operations without allocating arrays.

Each element is a KeyValuePair struct with:

  • .key: the key as a string
  • .val: reference to the value as a var

    Returns

    A PairRange over the object entries, or an empty range if this is not an object.

    Examples

    import std.algorithm : filter, map;
    import std.array : array;
    var obj;
    obj["a"] = 1;
    obj["b"] = 2;
    auto pairs = obj.byPair.filter!(p => p.val.as!int > 1).map!(p => p.key).array;
    assert(pairs == ["b"]);