All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.madgag.diff.MapDiff.scala Maven / Gradle / Ivy

There is a newer version: 3.5
Show newest version
package com.madgag.diff

object MapDiff {
  def apply[K,V](before: Map[K,V], after: Map[K,V]): MapDiff[K,V] =
    MapDiff(Map(Before -> before, After -> after))
}

case class MapDiff[K, V](beforeAndAfter: Map[BeforeAndAfter, Map[K,V]]) {

  lazy val commonElements: Set[K] = beforeAndAfter.values.map(_.keySet).reduce(_ intersect _)

  lazy val only: Map[BeforeAndAfter, Map[K,V]] =
    beforeAndAfter.mapValues(_.filterKeys(!commonElements(_)))

  lazy val (unchanged, changed) =
    commonElements.partition(k => beforeAndAfter(Before)(k) == beforeAndAfter(After)(k))

  lazy val unchangedMap: Map[K,V] = beforeAndAfter(Before).filterKeys(unchanged)

  lazy val changedMap: Map[K,Map[BeforeAndAfter, V]] =
    changed.map(k => k -> beforeAndAfter.mapValues(_(k))).toMap

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy