Created
May 14, 2019 18:55
-
-
Save dnaumenko/2bfeedeea09e2c6dc702cc0fded7b004 to your computer and use it in GitHub Desktop.
Shift util for Cats IO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from https://gitter.im/typelevel/cats-effect?at=5cdae78a5a887e1cd9e8a334 | |
trait Shifter[F[_]] { | |
def shiftFair[A](fa: F[A]): F[A] | |
} | |
def fairShifter(n: Int): F[Shifter[F]] = | |
Ref.of(0).map { | |
new Shifter[F] { | |
def shiftFair(fa: F[A]): F[A] = ref.modify(i => (i+1, i%n == 0).ifM(shift >> fa, fa) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment