Mathematically, the mapping might not be ivertible, e.g., from Map[A,B], you can't get Map[B,A], but rather you get Map[B,Iterable[A]], because there might be different keys associated with same values. So, if you are interested in knowing all the keys, here's the code:

Inverse is a better name for this operation than reverse (as in "inverse of a mathematical function")

I often do this inverse transformation not only on maps but on other (including Seq) collections. I find it best not to limit the definition of my inverse operation to one-to-one maps. Here's the definition I operate with for maps (please suggest improvements to my implementation).

I came here looking for a way to invert a Map of type Map[A, Seq[B]] to Map[B, Seq[A]], where each B in the new map is associated with every A in the old map for which the B was contained in A's associated sequence.