AtomicCell

abstract class AtomicCell[F[_], A]

A fiber-safe, concurrent, mutable reference.

Provides safe concurrent access and modification of its contents, by ensuring only one fiber can operate on them at the time. Thus, '''all''' operations may semantically block the calling fiber.

final class ParkingLot(data: AtomicCell[IO, ArraySeq[Boolean]], rnd: Random[IO]) {
  def getSpot: IO[Option[Int]] =
data.evalModify { spots =>
val availableSpots =
spots.view.zipWithIndex.collec {
case (idx, true) => idx
}.toList

rnd.shuffleList(availableSpots).map(_.headOption)
}
}
See also:

cats.effect.kernel.Ref for a non-blocking alternative.

Companion:
object
Source:
AtomicCell.scala
class Object
trait Matchable
class Any

Value members

Abstract methods

def evalGetAndUpdate(f: A => F[A]): F[A]

Updates the current value using the provided effectual function, and returns the previous value.

Updates the current value using the provided effectual function, and returns the previous value.

Source:
AtomicCell.scala
def evalModify[B](f: A => F[(A, B)]): F[B]

Like evalUpdate but allows the update function to return an output value.

Like evalUpdate but allows the update function to return an output value.

Source:
AtomicCell.scala
def evalUpdate(f: A => F[A]): F[Unit]

Like update but using an effectual function; which is guaranteed to run only once.

Like update but using an effectual function; which is guaranteed to run only once.

Source:
AtomicCell.scala
def evalUpdateAndGet(f: A => F[A]): F[A]

Updates the current value using the provided effectual function, and returns the updated value.

Updates the current value using the provided effectual function, and returns the updated value.

Source:
AtomicCell.scala
def get: F[A]

Obtains the current value.

Obtains the current value.

Source:
AtomicCell.scala
def modify[B](f: A => (A, B)): F[B]

Like update but allows the update function to return an output value.

Like update but allows the update function to return an output value.

Source:
AtomicCell.scala
def set(a: A): F[Unit]

Sets the current value to a.

Sets the current value to a.

Source:
AtomicCell.scala

Concrete methods

def getAndSet(a: A): F[A]

Replaces the current value with a, returning the previous value.

Replaces the current value with a, returning the previous value.

Source:
AtomicCell.scala
def getAndUpdate(f: A => A): F[A]

Updates the current value using the provided function, and returns the previous value.

Updates the current value using the provided function, and returns the previous value.

Source:
AtomicCell.scala
def update(f: A => A): F[Unit]

Modifies the current value using the supplied update function.

Modifies the current value using the supplied update function.

Source:
AtomicCell.scala
def updateAndGet(f: A => A): F[A]

Updates the current value using the provided function, and returns the updated value.

Updates the current value using the provided function, and returns the updated value.

Source:
AtomicCell.scala