Status/Resolution/Reason: To Fix//
Reporter/Name(from Bugbase): Abram Adams / Abram Adams (Abram Adams)
Created: 09/17/2015
Components: Language
Versions: 11.0
Failure Type: Unspecified
Found In Build/Fixed In Build: CF11_Final /
Priority/Frequency: Trivial / Unknown
Locale/System: ALL / Linux uBuntu 11.10
Vote Count: 6
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 (or the related member functions), 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]
If implemented, the + and & operators should also be able to perform the same actions in a immutable fashion. For example:
// initial struct
struct = { "a": 1, "b": 2 };
//...later
combinedStruct = struct + {
"key": "something",
"key2": "something else",
"key3": "something else",
"key4": "something else",
"a": 3
};
The resulting combinedStruct would be:
{
"a": 3,
"b": 2,
"key": "something",
"key2": "something else",
"key3": "something else",
"key4": "something else"
}
Likewise the & should be allowed, but in overwrite==false mode. Example:
// initial struct
struct = { "a": 1, "b": 2 };
//...later
combinedStruct = struct & {
"key": "something",
"key2": "something else",
"key3": "something else",
"key4": "something else",
"a": 3
};
The resulting combinedStruct would be:
{
"a": 1,
"b": 2,
"key": "something",
"key2": "something else",
"key3": "something else",
"key4": "something else"
}
----------------------------- Additional Watson Details -----------------------------
Watson Bug ID: 4058829
External Customer Info:
External Company:
External Customer Name: Abram Adams
External Customer Email:
Attachments:
Comments: