![]() |
|
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].
![]() ![]()
Question [2].
![]() ![]() ![]() |