updateVariable

inline fun <T : Any> updateVariable(noinline callback: VariableUpdateCallback<T>)

Runs callback for every snippet property of compile-time subtype of type T

callback gives access to both runtime value of the property and its KProperty object

callback should usually execute some code that:

  • has non-Unit result and return the name of result field

  • defines some variable and return its name

Original variable will then be reassigned to this new name.

For example:

updateVariable<MyType> { value, kProperty ->
// MyWrapper class should be previously defined in the notebook
execute("MyWrapper(${kProperty.name})").name
}

or

updateVariable<MyType> { value, kProperty ->
// MyWrapper class should be previously defined in the notebook
execute("val wrapper = MyWrapper(${kProperty.name})")
return "wrapper"
}