share

fun <Initial> AggregateContext.share(initial: Initial, transform: (Field<Initial>) -> Initial): Initial

share captures the space-time nature of field computation through observation of neighbours' values, starting from an initial value, it reduces to a single local value given a transform function and updating and sharing to neighbours of a local variable.

val result = share(0) {
it.maxBy { v -> v.value }.value
}
result // result: kotlin.Int

In the example above, the function share wil return a value that is the max found in the field.