scala / scala-library-next

backwards-binary-compatible Scala standard library additions
Apache License 2.0
69 stars 17 forks source link

Add `updateOrDelete` to immutable Maps #167

Closed Lasering closed 1 year ago

Lasering commented 1 year ago
def updateOrDelete[V1 >: V](key: K)(updateOrDelete: Option[V1]): Map[K, V1] =
  updateOrDelete match {
    case None => this.removed(key)
    case Some(value) => this.updated(key, value)
  }
BalmungSan commented 1 year ago

You can already do this using updatedWith like:

map.updatedWith(key)(_ => updateOrDelete)