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

de.lancom.openapi.tools.MergeMap.kt Maven / Gradle / Ivy

Go to download

This open-source project provides an OpenAPI 3.0 Parser implemented in Kotlin, utilizing immutable data classes

There is a newer version: 2.1.1
Show newest version
package de.lancom.openapi.tools

import de.lancom.openapi.entity.Entity

fun  mergeMap(left: Map, right: Map): Map {
    val allKeys = left.keys + right.keys

    return allKeys.associateWith { key ->
        val l = left[key]
        val r = right[key]

        when {
            l != null && r != null ->
                if (l is Entity && r is Entity) {
                    @Suppress("UNCHECKED_CAST")
                    l.mergeEntity(r) as V
                } else {
                    r
                }

            l != null ->
                l

            r != null ->
                r

            else ->
                TODO("Both values should not be null")
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy