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

commonMain.com.sunnychung.lib.multiplatform.kotlite.extension.MapExtension.kt Maven / Gradle / Ivy

Go to download

A Kotlin Multiplatform library to interpret Kotlite code, which is a subset of Kotlin language, in runtime in a safe way.

The newest version!
package com.sunnychung.lib.multiplatform.kotlite.extension

import com.sunnychung.lib.multiplatform.kotlite.error.DuplicateKeyException

infix fun  Map.merge(another: Map): Map {
    val result = mutableMapOf()
    this.toMap(result)
    another.forEach {
        if (result.containsKey(it.key)) {
            throw DuplicateKeyException("Duplicate key while merging maps")
        }
        result[it.key] = it.value
    }
    return result
}

infix fun  Map.mergeIfNotExists(another: Map): Map {
    val result = mutableMapOf()
    this.toMap(result)
    another.forEach {
        if (!result.containsKey(it.key)) {
            result[it.key] = it.value
        }
    }
    return result
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy