What is the best way to create a Map[K,V] from a Set[K] and function from K to V?
Map[K,V]
Set[K]
K
V
For example, suppose I have
In addition to the existing answers,
Map() ++ set.view.map(i => i -> f(i))
is pretty short and performs as well as the faster answers (fold/breakOut).
(Note the view to prevent creation of a new collection; it does the remapping as it goes.)