I am having trouble with syntax for partial function application. The following code works fine, and it outputs: two-three-four
import kotlin.coroutines.experimental.*
inline fun <T> Iterable<T>.forEachFrom(beg:Int, act:(T)->Unit) {
var i=0; if (beg>=0) for (e in this) if (i++ >= beg) act(e)
} // sample function I am testing; please don't change this!
fun main(a:Array<String>) {
val l = listOf("zero", "one", "two", "three", "four")
fun test() = buildSequence { l.forEachFrom(2) { yield(it) } }.joinToString("-")
println(test())
}
I'd like to encapsulate my test()
, so it is called as:
test(l.forEachFrom(2))
However, I can't seem to get the types/syntax right.
How would I re-write the test()
function definition to make this possible?