arrow-fx / arrow.fx / MVar / tryTake
abstract fun tryTake(): Kind<F, Option<A>>
Try to take the value of MVar, returns result as an Option.
import arrow.core.*
import arrow.fx.*
import arrow.fx.extensions.io.async.async
import arrow.fx.extensions.io.monad.flatMap
fun main(args: Array<String>) {
//sampleStart
val mvar = MVar.factoryUncancellable(IO.async())
mvar.just(5).flatMap { v ->
v.tryTake()
}.unsafeRunSync() == Some(5)
mvar.empty<Int>().flatMap { v ->
v.tryTake()
}.unsafeRunSync() == None
//sampleEnd
}
Do you like Arrow?
✖