Navigation
Synopsis Convert a list of tuples to a map; result must be a map.
Function map[&A,&B] toMapUnique(list[tuple[&A, &B]] lst) throws MultipleKey
Usage import List;
Description Convert a list of tuples to a map; result must be a map.
Examples
rascal>import List;
ok
rascal>toMapUnique([<1,10>, <2, 20>, <3, 30>]);
map[int, int]: (1:10,2:20,3:30)
Let's explore an error case:
rascal>toMapUnique([<1,10>, <1, 11>, <2, 20>, <3, 30>]);
|rascal://List|(27833,1003,<1353,0>,<1394,79>): MultipleKey(1)
	at *** somewhere ***(|rascal://List|(27833,1003,<1353,0>,<1394,79>))
	at toMapUnique(|stdin:///|(43,2,<1,43>,<1,45>))


Pitfalls The keys in a map are unique by definition. toMapUnique throws a MultipleKey exception when the list contains more than one tuple with the same first value.

Questions
Question [1].
The type of toMapUnique([<-3,4>,<19,3>,<-16,-11>,<-19,-6>,<1,6>,<0,19>]) is

Question [2].
toMapUnique([<-7,17>,<15,-9>,<13,7>,<7,-11>,<4,-9>,<1,-6>]) == 



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 ask.rascal-mpl.org.