How does Kotlins Map.minus work? I would have expected that the entries with the same key are removed.
fun main()
{
val left = mapOf(1 to "first", 2 to "second")
val right = mapOf(1 to "first")
val diff = left.minus(right)
println(left)
println(right)
println(diff)
}
Output:
{1=first, 2=second}
{1=first}
{1=first, 2=second}
Expected:
{1=first, 2=second}
{1=first}
{2=second}
From the Kotlin documentation:
Returns a map containing all entries of the original map except the entry with the given key. The returned map preserves the entry iteration order of the original map.