Beginner question — what do you usually use as a multimap? I want a function that takes a labelling function and partitions elements by each label. For example,
f x | x `mod` 2 == 0 = EVEN
| otherwise = ODD
the output of partition f lst where lst :: [Int] would be
EVEN --> [list of even numbers]
ODD --> [sublist of odd numbers]
Sorry for the bother, I could not find something similar on Hoogle. I think I can get there via Data.List.Key‘s group function, sort, and some mapping, but there must be a simpler way, no? This seems like a generally useful function.
When there are only two cases, you can map them to booleans and use
Data.List.partition.In the general case, you can use a
Data.Mapwith a list or set as the value type. You can build one easily usingData.Map.fromListWith.