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.
 */
@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
        }
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy