Skip to content

Instantly share code, notes, and snippets.

@TRBaldim
Created January 17, 2017 21:50
Show Gist options
  • Save TRBaldim/ca8cadecd0c97ff474c44c105817868a to your computer and use it in GitHub Desktop.
Save TRBaldim/ca8cadecd0c97ff474c44c105817868a to your computer and use it in GitHub Desktop.
Update Immutable Map in Scala
def updateMap[A, B](map: Map[A, List[B]], key: A, value: B) =
map + ((key, map.getOrElse(key, List()) ::: List(value)))
var topicsMap = offsetsRanges.map { o => (o.topic, List[String]())}.toMap
offsetsRanges.foreach { o =>
topicsMap = updateMap[String, String](topicsMap, o.topic, (o.partition + ":" + o.untilOffset))}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment