Atomic
An Atomic with an initial value of A.
Atomic wraps atomic, so that you can also use it on a top-level function or pass it around. In other languages this data type is also known as Ref, IORef or Concurrent safe Reference. So in case you don't need to pass around an atomic reference, or use it in top-level functions it's advised to use atomic from Atomic Fu directly.
import arrow.fx.coroutines.*
suspend fun main() {
val count = Atomic(0)
(0 until 20_000).parTraverse {
count.update(Int::inc)
}
println(count.get())
}Content copied to clipboard
Atomic also offers some other interesting operators such as modify, tryUpdate, access&lens.