Есть ли лучший способ создать экземпляр StateT[IO, S, A]
в объекте Impl
?
Редактировать: я его отредактировал, мне сейчас хорошо, можем ли мы лучше?
case class BusinessState()
trait BusinessResult
case object KeepGoing extends BusinessResult
case object StopNow extends BusinessResult
type IOState[S, A] = StateT[IO, S, A]
type BusinessIOState[A] = IOState[BusinessState, A]
trait SomeSteps {
def step1:BusinessIOState[Unit]
def step2:BusinessIOState[BusinessResult]
def program = for {
_ <- step1
businessResult <- step2
} yield businessResult
}
object Impl extends SomeSteps {
override def step1: BusinessIOState[Unit] = StateT { businessState =>
//do some processing
IO.pure((businessState, Unit))
}
override def step2: BusinessIOState[BusinessResult] = StateT { businessState =>
//do some processing
IO.pure((businessState, KeepGoing))
}
}
println(Impl.program.run(BusinessState()).unsafeRunSync())