Skip to content

Instantly share code, notes, and snippets.

@softberries
Created June 24, 2020 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save softberries/49b6c79c31b1ce6c21bd33c615adf7d0 to your computer and use it in GitHub Desktop.
Save softberries/49b6c79c31b1ce6c21bd33c615adf7d0 to your computer and use it in GitHub Desktop.
def modify[B](f: A => (A, B)): F[B] = {
@tailrec
def spin: B = {
val c = ar.get
val (u, b) = f(c)
if (!ar.compareAndSet(c, u)) spin
else b
}
F.delay(spin)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment