org.jetbrains.kotlinx.jupyter.util.LibraryProcessing.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-jupyter-api Show documentation
Show all versions of kotlin-jupyter-api Show documentation
API for libraries supporting Kotlin Jupyter notebooks
package org.jetbrains.kotlinx.jupyter.util
import org.jetbrains.kotlinx.jupyter.api.libraries.CodeExecution
import org.jetbrains.kotlinx.jupyter.api.libraries.VariablesSubstitutionAware
/**
* Replace all $ substrings in [str] with corresponding
* [mapping] values
*/
fun replaceVariables(
str: String,
mapping: Map,
) = mapping.asSequence().fold(str) { s, template ->
s.replace("\$${template.key}", template.value)
}
@JvmName("replaceVariablesString")
fun Iterable.replaceVariables(mapping: Map) = map { replaceVariables(it, mapping) }
@JvmName("replaceVariables")
fun > Iterable.replaceVariables(mapping: Map) = map { it.replaceVariables(mapping) }
@JvmName("replaceVariablesExecution")
fun Iterable.replaceVariables(mapping: Map) = map { it.toExecutionCallback(mapping) }