parameter

fun <T> ParameterizeScope.parameter(arguments: Sequence<T>): ParameterizeScope.Parameter<T>(source)
fun <T> ParameterizeScope.parameter(arguments: Iterable<T>): ParameterizeScope.Parameter<T>(source)

Declare a parameter with the given arguments.

val letter by parameter('a'..'z')

@JvmName(name = "parameterLazySequence")
inline fun <T> ParameterizeScope.parameter(crossinline lazyArguments: LazyParameterScope.() -> Sequence<T>): ParameterizeScope.Parameter<T>(source)
@JvmName(name = "parameterLazyIterable")
inline fun <T> ParameterizeScope.parameter(crossinline lazyArguments: LazyParameterScope.() -> Iterable<T>): ParameterizeScope.Parameter<T>(source)

Declares a parameter with the given lazyArguments. The arguments are only computed the first time the parameter is used, and not at all if used.

This parameter function is useful to avoid computing the arguments every iteration. Instead, these arguments will only be computed the first time the parameter is used.

val evenNumberSquared by parameter {
numbers
.filter { it % 2 == 0 }
.map { it * it }
}

Restrictions

  • The lazyArguments block should not have side effects. Since it's not run every iteration, side effects could make the execution different from future iterations, breaking parameterize's determinism assumption.