ComputedValue

abstract class ComputedValue<out T> : Computation(source)

Computed value for values of type T.

Computed values should depend on other values. These dependencies may be defined via the dependency function, by providing the path of the dependency relative to the value being computed.

Example computed value which computes the sum between two other values:

object MySum : ComputedValue<Int>() {
private val ComputedValueContext.value1: Int? by dependency("../value1")
private val ComputedValueContext.value2: Int? by dependency("../value2")

override suspend fun ComputedValueContext.compute(): Int = (value1 ?: 0) + (value2 ?: 0)
}

Inheritors

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
open override val dependencies: Map<String, DependencyInfo>

Dependencies of the computed value. Mapping of keys to the paths this computed value depends on. Keys can be used within a ComputedValueContext to access the value of the dependencies.

Link copied to clipboard

Set of external context dependencies of the computed value.

Link copied to clipboard

Schema of the value being computed.

Functions

Link copied to clipboard
@JvmName(name = "reifiedAddDependency")
protected inline fun <TDependency> addDependency(dependencyKey: String, path: String)
protected fun addDependency(dependencyKey: String, path: String)
@JvmName(name = "reifiedAddDependency")
protected inline fun <TDependency> addDependency(dependencyKey: String, path: Path)
protected fun addDependency(dependencyKey: String, path: Path)

Declares a dependency to path, accessible in the computed value's context via key dependencyKey.

Link copied to clipboard
protected fun addExternalContextDependency(externalContextName: String)

Declares an external context dependency to externalContextName.

Link copied to clipboard
abstract suspend fun ComputedValueContext.compute(): T

Runs the computation within a ComputedValueContext containing the value of all declared dependencies. Returns the computed value.

Link copied to clipboard

Function used to declare a dependency to a path and delegate access to its value within a ComputedValueContext.

Link copied to clipboard

Function used to declare a dependency to a path and delegate access to its value within a ComputedValueContext.

Link copied to clipboard

Function used to declare a dependency to an external context and delegate access to its value within a ComputedValueContext.

Link copied to clipboard

Function used to declare a dependency to an external context and delegate access to its value within a ComputedValueContext.

Link copied to clipboard
open override fun toString(): String