All Downloads are FREE. Search and download functionalities are using the official Maven repository.

kotlin.util.Functions.kt Maven / Gradle / Ivy

There is a newer version: 1.0.7
Show newest version
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