set
Set the value of a TVar.
import arrow.fx.stm.TVar
import arrow.fx.stm.atomically
suspend fun main() {
//sampleStart
val tvar = TVar.new(10)
val result = atomically {
tvar.set(20)
}
//sampleEnd
println(result)
}
Content copied to clipboard
Similarly to value this comes with a few guarantees:
For multiple writes to the same TVar in a transaction only the last will actually be performed
When committing the value inside the TVar, at the time of calling set, has to be the same as the current value otherwise the transaction will retry
Set a variable in the TArray.
import arrow.fx.stm.TArray
import arrow.fx.stm.atomically
suspend fun main() {
//sampleStart
val tarr = TArray.new(size = 10, 2)
val result = atomically {
tarr[5] = 3
tarr[5]
}
//sampleEnd
println("Result $result")
}
Content copied to clipboard
Throws if i is out of bounds.
This function never retries.
Alias for STM.insert
import arrow.fx.stm.TMap
import arrow.fx.stm.atomically
suspend fun main() {
//sampleStart
val tmap = TMap.new<Int, String>()
atomically {
tmap[1] = "Hello"
}
//sampleEnd
}
Content copied to clipboard