TickingValue

data class TickingValue<out T>(val value: T, val nextTick: Duration?)(source)

This class holds a value of type T and a Duration that indicates how much time needs to pass before recalculating value is required (i.e. how long since its production nextTick is valid for).

Note: this class purposefully does track the date/time when the value "expires", but simply provides a Duration indicating how long the value is valid for. It is a responsibility of callers to keep track when the value needs to be recomputed. For this reason, storing or transmitting this class via methods that require a significant delay (e.g. over a network) is not recommended.

Parameters

value

the value

nextTick

after how much time the next value should be re-computed. null means that no more computations are needed.

Constructors

Link copied to clipboard
constructor(value: T, nextTick: Duration?)

Properties

Link copied to clipboard
Link copied to clipboard
val value: T

Functions

Link copied to clipboard
fun <T1, T2, R> TickingValue<T1>.combine(other: TickingValue<T2>, transform: (T1, T2) -> R): TickingValue<R>

Combines two different TickingValues.

Link copied to clipboard
fun <T, R> TickingValue<T>.flatMap(transform: (T) -> TickingValue<R>): TickingValue<R>

Transforms this TickingValue using the transform function. The resulting TickingValue.nextTick will be the min of the two, see also withNextTickAtMost.

Link copied to clipboard
fun <T, R> TickingValue<T>.map(transform: (T) -> R): TickingValue<R>

Transforms the TickingValue.value from this instance from type T to R using transform and returns a new TickingValue with it and the same TickingValue.nextTick.

Link copied to clipboard

Returns a TickingValue with the same TickingValue.value and with the next tick being the min of its value and nextTick.