
kotlin.util.Functions.kt Maven / Gradle / Ivy
package kotlin
/**
* Converts a function that takes one argument and returns a value of the same type to a generator function.
* The generator function calls this function, passing to it either [initialValue] on the first iteration
* or the previously returned value on subsequent iterations, and returns the returned value.
*/
public fun Function1.toGenerator(initialValue: T): Function0 {
var nextValue: T? = initialValue
return {
nextValue?.let { result ->
nextValue = this@toGenerator(result)
result
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy