Last active
December 22, 2015 00:09
-
-
Save fsvehla/6387428 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def transformKeys[A,B,C](m: Map[A, B], transformFunc: (A => C)): Map[C, B] = { | |
m.foldLeft(Map.empty[C, B]) { (acc, entry) => | |
acc + (transformFunc(entry._1) -> entry._2) | |
} | |
} | |
val numMap: Map[Int, String] = Map(1 -> "Two", 2 -> "Four", 3 -> "Six") | |
val transformed = transformKeys(numMap, { (key:Int) => key * 2 }) | |
// without (key:Int) = error: missing parameter type |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment