Status/Resolution/Reason: Closed/Withdrawn/Duplicate
Reporter/Name(from Bugbase): Abram Adams / Abram Adams (Abram Adams)
Created: 03/09/2016
Components: Language
Versions: 2016
Failure Type: Unspecified
Found In Build/Fixed In Build: Alpha_v12 /
Priority/Frequency: Trivial / Unknown
Locale/System: English / Linux All
Vote Count: 5
Duplicate ID: CF-4058829
Quite often I’m working with arrays and structs and have the need to either add or override keys/indexes to a struct/array. To add a key, I can simply do struct["key"] = "something"; or struct.key = something. However, there are many times when I’m adding/updating a lot of keys and have to do:
// initial struct
struct = { "a": 1, "b": 2 };
//...later
struct["key"] = "something";
struct["key2"] = "something else";
struct["key3"] = "something else";
struct["key4"] = "something else";
struct["a"] = 2;
Now, I know I can structAppend or arrayAppend, but it would be really handy if I could use &= and += in arrays/structs so that I could inline updating or appending to these data types.
In my mind the &= would be synonymous for structAppend() with the overwrite flag off and += would be with the overwrite flag on. With these one would be able to turn the struct example above into:
// initial struct
struct = { "a": 1, "b": 2 };
//...later
struct &= {
"key": "something",
"key2": "something else",
"key3": "something else",
"key4": "something else",
"a": 3
};
The resulting struct would be:
{
"a": 1,
"b": 2,
"key": "something",
"key2": "something else",
"key3": "something else",
"key4": "something else"
}
because &= behaves as overwrite=false. While the following would overwrite:
// initial struct
struct = { "a": 1, "b": 2 };
//...later
struct += {
"key": "something",
"key2": "something else",
"key3": "something else",
"key4": "something else",
"a": 3
};
The resulting struct would be:
{
"a": 3,
"b": 2,
"key": "something",
"key2": "something else",
"key3": "something else",
"key4": "something else"
}
The arrayAppend version would treat &= as merge=false and += as merge=true. Example:
// initial array
array = [1,2,3];
//...later
array &= [3,5,7];
This would end up with an array like:
[1,2,3,[3,5,7]]
With +=:
// initial array
array = [1,2,3];
//...later
array += [3,5,7];
It would end up with an array like:
[1,2,3,3,5,7]
----------------------------- Additional Watson Details -----------------------------
Watson Bug ID: 4126636
External Customer Info:
External Company: CFXchange.com
External Customer Name: Abram Adams
External Customer Email: AADAMS@CFXCHANGE.COM
External Test Config:
Attachments:
Comments: