commonMain.org.jetbrains.letsPlot.intern.OptionsUtil.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lets-plot-kotlin-kernel Show documentation
Show all versions of lets-plot-kotlin-kernel Show documentation
Lets-Plot Kotlin API without dependencies.
package org.jetbrains.letsPlot.intern
internal object OptionsUtil {
fun toSpec(optionList: List): Map? {
return optionList
.map(OptionsMap::toSpec)
.reduceOrNull { prev, next -> mergeOptions(prev, next).toMutableMap() }
}
fun mergeOptions(m0: Map, m1: Map): Map {
val overlappingKeys = m0.keys.intersect(m1.keys)
val keysToMerge = overlappingKeys.filter {
m0[it] is Map<*, *> && m1[it] is Map<*, *>
}
val m2 = keysToMerge.associateWith {
(m0[it] as Map<*, *> + m1[it] as Map<*, *>)
}
return m0 + m1 + m2
}
}