commonMain.org.jetbrains.letsPlot.intern.OptionsUtil.kt Maven / Gradle / Ivy
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
}
}