Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main(args: Array[String]): Unit = {
- val stateProgram : IndexedStateT[Eval, Counter, Counter, Int] = for {
- _ <- increaseCount(10)
- count1 <- getCount
- _ <- increaseCount(5)
- count2 <- getCount
- } yield count1 + count2
- stateProgram.run(Counter(100)).map(state => IO(println(state))).value.unsafeRunSync()
- }
- case class Counter(int: Int = 0)
- def increaseCount(by: Int = 1): State[Counter, Unit] = State[Counter, Unit](counter =>
- (counter.copy(counter.int + by), ())
- )
- def getCount: State[Counter, Int] = State[Counter, Int](c => (c, c.int))
Add Comment
Please, Sign In to add comment