modify

suspend fun <A> TVar<A>.modify(f: (A) -> A): A(source)

Atomically reads and updates a TVar using the given function f.

Example:

val counter = TVar.new(0)
val newValue = counter.modify { it + 1 } // 1

Return

the new value after applying f

Parameters

f

a transformation function applied to the current value