ScriptedValues

class ScriptedValues<T>(values: List<T>, exhaustion: ScriptedValues.Exhaustion<T> = Exhaustion.Fail)(source)

A deterministic sequence of values, such as dates or IDs, with an explicit exhaustion policy.

Safe to share between threads: each value is handed out once, in order.

val ids = ScriptedValues(listOf("a", "b"), ScriptedValues.Exhaustion.Fail)
val repository = Repository(newId = ids::next)

Parameters

values

Values to hand out in order; an empty script is permitted.

exhaustion

The behavior after the last value; defaults to failing.

Constructors

Link copied to clipboard
constructor(values: List<T>, exhaustion: ScriptedValues.Exhaustion<T> = Exhaustion.Fail)

Types

Link copied to clipboard
class Exhausted(val consumedCount: Int) : IllegalStateException

Thrown when a script runs out of values and its policy supplies no replacement.

Link copied to clipboard
sealed interface Exhaustion<out T>

Behavior after every supplied value has been consumed.

Properties

Link copied to clipboard

The number of supplied values that have not been consumed.

Functions

Link copied to clipboard
fun next(): T

Consumes the next value or applies the exhaustion policy.