Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Reword put() and fix example

...

The put() operator takes two arguments: a an optional hash path, and a new element to be inserted. The element must itself be a map. The result is a new data a structure with the element inserted at the location specified by the hash path. If the path specifies a location that does not exist, it will be created. If the location already has a value, it will be replaced by the new element. For example:

Code Block
languagejavascript
themeConfluence
a = { "colors" : "many",
      "pi" : [3,1,4,1,5,6,9]
    };
b = {"flop" : 12};
c = a.put(["foo"], b);
// c = { "colors" : "many",
//       "pi" : [3,1,4,1,5,6,9],
//       "foo" : {"flop" : 12}
//     };
d = a.put(["foo", "bar"], b);
// d = { "colors" : "many",
//       "pi" : [3,1,4,1,5,6,9],
//       "foo" : {"bar" : {"flop" : 12}}
// };

If the first argument is missing (i.e. there is only one argument) then the path is take to be the root and the item is put hash path is omitted, the element must be a map, and its keys and values will be merged at the root level of the map:

Code Block
languagejavascript
themeConfluence
e = a.put(b);
// ae = {"colors" : "many",
//      "pi" : [3,1,4,1,5,6,9]
//      "flop" : 12
//     };

...