Advertisement
Guest User

Untitled

a guest
Apr 10th, 2023
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.27 KB | Source Code | 0 0
  1. class Generator {
  2.   val state: IO[Ref[IO, Int]] = IO.ref(33)
  3.  
  4.   def generate: IO[Int] =
  5.     for {
  6.       delta <- IO.delay { scala.util.Random.nextInt(10) }
  7.       _ <- state.flatMap(state => state.update(_ + delta))
  8.       newVal <- state.flatMap(_.get)
  9.     } yield newVal
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement