Operator Type:
Operator Scope of Action:
Operator Purpose:
Data Type Returned:
Operator First Added:
Operator in Current Baseline:
Operator Last Altered:
Function [other Function type actions]
Item [operators of similar scope]
Dictionary, Set & List operations [other Dictionary, Set & List operations operators]
Dictionary [about Dictionary data type]
v9.1.0
Baseline
9.5.2
Dictionary.extend(itemDict)
This reads a Dictionary-type argument itemDict from which a key and a value are parsed. It adds the value string to the value(s) of a key.
If key does not exist, that key is created with a value of value.
If key exists, value is appended to key's existing value(s).
Assume $MyDictionary has no 'pear' key. Example:
$MyDictionary = $MyDictionary.extend({pear:fruit});
The key 'pear' is added and now has value 'fruit'. Next:
$MyDictionary = $MyDictionary.extend({pear:green});
The key 'pear' now has an additional new value 'green', but the overall value is now a list and the key:value pair is pear:fruit;green
.
To set the new valueStr so it replaces all existing value(s) see Dictionary.add().
Note that quotes are not used around either/both the keyStr and valueStr. The .extend() operator accepts quoted strings. The following expressions are equivalent:
$MyDictionary.extend({1:able})
$MyDictionary.extend("{1:able}")
But do not use either of the following example syntax:
WRONG!$MyDictionary.extend({"1:able"})
WRONG!$MyDictionary.extend({"1":"able"})
Dictionary.extend(keyStr, valueStr)
This adds the valueStr string to the value(s) of a keyStr.
If keyStr does not exist, that key is created with a value of valueStr.
If keyStr exists, valueStr is appended to keyStr's existing value(s).
Assume $MyDictionary has no 'pear' keyStr. Example:
$MyDictionary = $MyDictionary.extend("pear","fruit");
The keyStr 'pear' is added and now has valueStr 'fruit'. Next:
$MyDictionary = $MyDictionary.extend("pear","green");
The keyStr 'pear' now has an additional new valueStr 'green', but the overall value is now a list and the key:value air is pear:fruit;green
.
To set the new valueStr so it replaces all existing value(s) see Dictionary.add().
Dictionary.extend(dictStr)
The Dictionary.extend() operator takes a single argument, a dictionary—using the new {} syntax of key:pair elements which will extend the current elements.
$MyDictionary = $MyDictionary.extend({pear:green});
Note that quotes may be used around either/both the keyStr and valueStr. The following expressions are equivalent:
$MyDictionary = $MyDictionary.extend({1:able}};
$MyDictionary = $MyDictionary.extend("{1:able}"};
But do not use either of the following example syntax:
$MyDictionary = $MyDictionary.extend({"1:able"}};
WRONG!
$MyDictionary = $MyDictionary.extend({"1":"able"}};
WRONG!
Using offset addresses within itemDict
Either the keyStr or the valueStr may need to be calculated variable, for instance the valueStr might need to be the value of an offset attribute reference, e.g. $MyString("Some note")
, or inside a loop e.g. $MyString(loopVar)
. These expressions cannot be resolved within the .extend() operator but itemDict can be a variable. Thus, in a loop, rather than:
WRONG!vDict = vDict.extend({$Name(aState)+":"+$Color(aState)});
use:
vList.each(aState){
var:string vPair = $Name(aState)+":"+$Color(aState);
vDict = vDict.extend({vPair});
};
See also—notes linking to here: