recurse

fun recurse(body: (() -> Unit) -> Unit)

Invoke the given function with another function which will, when evaluated, do this again.

Parameters

body

The function itself.


fun <A> recurse(argument: A, body: (A, (A) -> Unit) -> Unit)

Invoke the given function with a supplied argument and another function which, when invoked, will once again invoke the original function with the new argument, etc.

This is handy for making it possible to re-invoke the original continuation from within itself (either in the same Thread or another). This bypasses a Java Catch-22 whereby only final variables can be accessed from a lambda, but the lambda can't be stored in a final variable if its definition refers to that variable.

Parameters

A

The type of the argument.

argument

The first argument to pass to the body.

body

The function to invoke.