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

org.jetbrains.kotlinx.jupyter.util.LibraryProcessing.kt Maven / Gradle / Ivy

There is a newer version: 0.12.0-335
Show newest version
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) }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy