Synopsis Invert the (key,value) pairs in a map.
Function map[&V, &K] invertUnique(map[&K, &V] M)
Usage import Map;
Description Returns a map with key and value inverted; the result should be a map. If the initial map contains duplicate values, the MultipleKey exception is raised since an attempt is made to create a map where more than one value would be associated with the same key.

Also see Map/invert and Exception.
rascal>import Map;
rascal>invertUnique(("apple": 1, "pear": 2, "orange": 3));
map[int, str]: (1:"apple",2:"pear",3:"orange")
Here is an examples that generates an exception:
rascal>invertUnique(("apple": 1, "pear": 2, "orange": 1));
|rascal://Map|(2677,682,<125,0>,<146,54>): MultipleKey(1)
	at *** somewhere ***(|rascal://Map|(2677,682,<125,0>,<146,54>))
	at invertUnique(|stdin:///|(47,1,<1,47>,<1,48>))

Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit