mplatvoet
10/29/2015, 1:19 PM//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)
}
}