![]() |
|
Navigation |
Synopsis Convert a list of pairs to a map; first elements are associated with a set of second elements.
Function
map[&A,set[&B]] toMap(list[tuple[&A, &B]] lst) throws MultipleKey
Usage
import List;
Description Convert a list of tuples to a map in which the first element of each tuple is
associated with the set of second elements from all tuples with the same first element. Keys should be unique.
Examples
rascal>import List; ok rascal>toMap([<1,10>, <1, 11>, <2, 20>, <3, 30>, <3, 31>]); map[int, set[int]]: ( 1:{10,11}, 2:{20}, 3:{30,31} )
Pitfalls
toMap collects all values in tuples with the same first value in a set.
Contrast this with toMapUnique that associates each first tuple value with the second tuple value,
but imposes the constraint that those keys are unique.
Questions
Question [1].
![]() ![]()
Question [2].
![]() ![]() ![]() |