Are there any thought about supporting continuatio...
# language-proposals
m
Are there any thought about supporting continuations in Kotlin? I've searched/glanced through the issue tracker but didn't find anything. My thoughts on this are as follows:
Copy code
//value, b are (any length) arbitrary arguments
//next is required last param
// N = return type of the complete continuation (last argument of function on which this is used in)
// R = result of this function
continuation fun <N, R> myContinuation(value:R, b : String, next: (R) -> N) : R {
    //do something before next, replace next or whatever
    return next(value)
}

//some piece of code
fun main(args: Array<String>) {
    val a = foo()
    bar(a)
}

///intruducing a continuation method
// this is what developers write
fun main(args: Array<String>) {
    val a = foo()
    val b = myContinuation(1, "b") //! no next function !
    bar(a)
}

///will be effectively compiled/rewritten as
// this is what the compiler produces
fun main(args: Array<String>) {
    val a = foo()
    myContinuation(1, "b") {
       val b = it
       bar(a)
    }
}