KVal

open class KVal<T>(value: T) : AutoCloseable(source)

A KVal is a read-only observable container for a value of type T. These are typically created by KVal.map or KVar.map, but can also be created directly.

Inheritors

Constructors

Link copied to clipboard
constructor(value: T)

Properties

Link copied to clipboard
open val value: T

The current value of this KVal, this can be read but not modified - but it may change if this KVal was created by mapping another KVal or using KVal.map. If you want to modify this value then you should be using a KVar instead.

Functions

Link copied to clipboard
fun addListener(listener: (T, T) -> Unit): Long

Add a listener to this KVar. The listener will be called whenever the value property changes.

Link copied to clipboard
open override fun close()

fun close(reason: CloseReason)

Close this KVal, and notify all handlers that it has been closed.

Link copied to clipboard
fun <O> map(mapper: (T) -> O): KVal<O>

Create another KVal that is a mapping of this KVal. The mapping function will be called whenever this KVal changes, and the new KVal will be updated with the result of the mapping function.

Link copied to clipboard
fun onClose(handler: () -> Unit)

Add a handler to be called when this KVal is closed.

Link copied to clipboard
operator fun <O : Any> KVal<List<O>>.plus(other: KVal<List<O>>): KVal<List<O>>
Link copied to clipboard
fun removeListener(handle: Long)

Remove a listener from this KVar. The listener will no longer be called when the value property changes.

Link copied to clipboard
fun <T : Any> KVal<List<T>>.subList(fromIx: Int, toIx: Int): KVal<List<T>>
Link copied to clipboard
open override fun toString(): String