tracker issue : CF-4126636

select a category, or use search below
(searches all categories and all time range)
Title:

Language/Syntax Enhancement - Array/Struct Literal append/update

| View in Tracker

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:

Adding BUG AUDIT TRAIL ********action: updated fieldName: Reason newValue: Duplicate oldValue: Blank oprid: rukumar recordName: RQ_DEFECT timpestamp: 2015-09-22 07:57:34.0 action: updated fieldName: Duplicate Bug ID newValue: CF-4058829 oldValue: Blank oprid: rukumar recordName: RQ_DEFECT timpestamp: 2015-09-22 07:57:34.0 action: updated fieldName: State newValue: Closed oldValue: Open oprid: rukumar recordName: RQ_DEFECT timpestamp: 2015-09-22 07:57:34.0 action: updated fieldName: Status newValue: Withdrawn oldValue: NeedsReview oprid: rukumar recordName: RQ_DEFECT timpestamp: 2015-09-22 07:57:34.0 action: updated fieldName: Owner newValue: Blank oldValue: rukumar oprid: rukumar recordName: RQ_DEFECT timpestamp: 2015-09-22 07:57:34.0 action: updated fieldName: Closed By newValue: rukumar oldValue: Blank oprid: rukumar recordName: RQ_DEFECT timpestamp: 2015-09-22 07:57:34.0 action: updated fieldName: Date Closed newValue: 2015-09-22 00:57:34.0 oldValue: Blank oprid: rukumar recordName: RQ_DEFECT timpestamp: 2015-09-22 07:57:34.0 action: updated fieldName: Fix By Product Milestone newValue: Beta oldValue: Blank oprid: inoel recordName: RQ_DEFECT timpestamp: 2015-09-21 04:19:13.0 action: updated fieldName: Fix By Milestone newValue: Beta oldValue: Blank oprid: inoel recordName: RQ_DEFECT timpestamp: 2015-09-21 04:19:13.0 action: updated fieldName: Duplicate Bug ID newValue: Blank oldValue: Blank oprid: inoel recordName: RQ_DEFECT timpestamp: 2015-09-21 04:17:29.0 action: updated fieldName: Status newValue: NeedsReview oldValue: Unverified oprid: inoel recordName: RQ_DEFECT timpestamp: 2015-09-16 05:05:57.0 action: updated fieldName: Reason newValue: Blank oldValue: Blank oprid: inoel recordName: RQ_DEFECT timpestamp: 2015-09-16 05:05:57.0 action: updated fieldName: Severity newValue: 0 oldValue: 1 oprid: inoel recordName: RQ_DEFECT timpestamp: 2015-09-16 05:05:57.0 action: updated fieldName: Owner newValue: rukumar oldValue: inoel oprid: inoel recordName: RQ_DEFECT timpestamp: 2015-09-16 05:05:57.0 action: added fieldName: Vote Type newValue: BETA oldValue: Blank oprid: prerelease recordName: AD_DEFECT_VOTE timpestamp: 2015-09-13 22:16:00.0 action: added fieldName: Vote Type newValue: BETA oldValue: Blank oprid: prerelease recordName: AD_DEFECT_VOTE timpestamp: 2015-09-13 16:39:08.0 action: added fieldName: Vote Type newValue: BETA oldValue: Blank oprid: prerelease recordName: AD_DEFECT_VOTE timpestamp: 2015-09-12 08:59:33.0 action: added fieldName: Vote Type newValue: BETA oldValue: Blank oprid: prerelease recordName: AD_DEFECT_VOTE timpestamp: 2015-09-11 23:23:07.0 action: added fieldName: Vote Type newValue: BETA oldValue: Blank oprid: prerelease recordName: AD_DEFECT_VOTE timpestamp: 2015-09-11 23:03:32.0
Comment by CFwatson U.
3661 | March 09, 2016 04:21:33 AM GMT
+1 ...This would be a nice addition.
Vote by External U.
3663 | March 09, 2016 04:21:35 AM GMT
sounds like a neat idea and enhances the language a little more.
Vote by External U.
3664 | March 09, 2016 04:21:37 AM GMT
Nice idea. Am not entirely convinced by the &= version being the best way to imply that functionality, that said. But am stll behind it as a general idea.
Vote by External U.
3665 | March 09, 2016 04:21:38 AM GMT
This language enhancement would be a real time saver.
Vote by External U.
3666 | March 09, 2016 04:21:41 AM GMT
This would be an excellent addition to the language, as they are common operations and these suggested operators save a lot of typing -- and still have intuitive meanings.
Vote by External U.
3667 | March 09, 2016 04:21:42 AM GMT
Added By:inoel Note Added: The duplicate bug #CF-4058829 also makes the case for immutable operations if + / & for structs / arrays are implemented. 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" } Date Added :2015-09-21 04:17:29.0 Added By: PreRelease User User Name:A. Bakia Note Added: Sorry, I consider the operators, &= and +=, inappropriate between two arrays or two structures. That is because these are complex types (objects). Whereas the operators imply simple types, being natural extensions of & and +, respectively. Date Added :2015-09-16 14:50:18.0 Added By: PreRelease User User Name:Abram Adams Note Added: Entered Bug. Date Added :2015-09-11 22:40:40.0
Comment by CFwatson U.
3662 | March 09, 2016 04:21:44 AM GMT