//arrow-fx-stm/arrow.fx.stm/STM/member

member

common open fun <K, V> TMap<K, V>.member(k: K): Boolean

Check if a key k is in the map

import arrow.fx.stm.TMap
import arrow.fx.stm.atomically

suspend fun main() {
  //sampleStart
  val tmap = TMap.new<Int, String>()
  atomically {
    tmap[1] = "Hello"

    tmap.remove(1)
  }
  //sampleEnd
}

This function never retries.

common open fun <A> TSet<A>.member(a: A): Boolean

Check if an element is already in the set

import arrow.fx.stm.TSet
import arrow.fx.stm.atomically

suspend fun main() {
  //sampleStart
  val tset = TSet.new<String>()
  val result = atomically {
    tset.insert("Hello")
    tset.member("Hello")
  }
  //sampleEnd
  println("Result $result")
}

Do you like Arrow?

Arrow Org
<