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.
*/
@Deprecated("This function will be removed soon. If you need generator function to create a sequence, use the 'sequence' function instead.")
public fun Function1.toGenerator(initialValue: T): Function0 {
var nextValue: T? = initialValue
return {
nextValue?.let { result ->
nextValue = this@toGenerator(result)
result
}
}
}