meldInto

Takes two associative arrays and melds them together, making a union of the two.

This is largely the same as the array-version meldInto but doesn't need the extensive template constraints it employs, so it might as well be kept separate.

  1. void meldInto(QualThing meldThis, Thing intoThis)
  2. void meldInto(Array1 meldThis, Array2 intoThis)
  3. void meldInto(QualAA meldThis, AA intoThis)
    pure
    void
    meldInto
    (
    QualAA meldThis
    ,
    ref AA intoThis
    )
    if (
    isAssociativeArray!AA &&
    is(QualAA : AA)
    &&
    isMutable!AA
    )

Parameters

strategy

To what extent the source object should overwrite set (non-init) values in the receiving object.

meldThis QualAA

Associative array to meld (source).

intoThis AA

Reference to the associative array to meld (target).

Examples

int[string] aa1 = [ "abc" : 42, "def" : -1 ];
int[string] aa2 = [ "ghi" : 10, "jkl" : 7 ];
arr1.meldInto(arr2);

assert("abc" in aa2);
assert("def" in aa2);
assert("ghi" in aa2);
assert("jkl" in aa2);
bool[string] aa1;
bool[string] aa2;

aa1["a"] = true;
aa1["b"] = false;
aa2["c"] = true;
aa2["d"] = false;

assert("a" in aa1);
assert("b" in aa1);
assert("c" in aa2);
assert("d" in aa2);

aa1.meldInto!(MeldingStrategy.overwriting)(aa2);

assert("a" in aa2);
assert("b" in aa2);

string[string] saa1;
string[string] saa2;

saa1["a"] = "a";
saa1["b"] = "b";
saa2["c"] = "c";
saa2["d"] = "d";

saa1.meldInto!(MeldingStrategy.conservative)(saa2);
assert("a" in saa2);
assert("b" in saa2);

saa1["a"] = "A";
saa1.meldInto!(MeldingStrategy.aggressive)(saa2);
assert(saa2["a"] == "A");

Meta