arrow-fx / arrow.fx / Dequeue / tryPeek
abstract fun tryPeek(): Kind<F, Option<A>>
Tries to peek a value from the Queue. Returns immediately with either None or a value Some. In contrast to tryTake, tryPeek does not remove the value from the Queue.
import arrow.fx.*
import arrow.fx.extensions.fx
//sampleStart
suspend fun main(args: Array<String>): Unit = IO.fx {
val queue = !Queue.unbounded<Int>()
val none = !queue.tryPeek()
!queue.offer(1)
val one = !queue.tryPeek()
val one2 = !queue.tryPeek()
!effect { println("none: $none, one $one, one2: $one2") }
}.suspended()
//sampleEnd
See Also
Do you like Arrow?
✖