Created
July 16, 2013 00:20
-
-
Save behaghel/6004735 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
implicit class RichMap[K, V](m: Map[K, V]) { | |
def updateValue(k: K)(f: Option[V] => V): Map[K, V] = m + (k -> f(m get k)) | |
def incValue(k: K)(implicit ev: Numeric[V]): Map[K, V] = | |
updateValue(k){ o => | |
val one = ev.fromInt(1) | |
o map { ev.plus(_, one) } getOrElse one | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment