Last active
December 29, 2022 15:01
-
-
Save qingwei91/0c939744a50b587ceee60ca5c28f406b to your computer and use it in GitHub Desktop.
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
import cats.effect._ | |
import scala.concurrent.duration._ | |
def addCoffeePowder(pot: Pot): IO[Pot] = ??? | |
def addWater(pot: Pot): IO[Pot] = ??? | |
def waitUntilBoil(heatedPot: Pot): StateT[IO, Unit, FiniteDuration] = ??? | |
def makeCoffee(pot: Pot): IO[Coffee] = { | |
for { | |
withCoffeePwd <- addCoffeePowder(pot) | |
withWater <- addWater(withCoffeePwd) | |
heatedPot <- turnOnHeat(withWater) | |
_ <- waitUntilBoil(heatedPot) // wont compile | |
coffee <- pot.pourCoffee | |
} yield coffee | |
} | |
----------- | |
def addCoffeePowder[F[_]](pot: Pot): F[Pot] = ??? | |
def addWater[F[_]](pot: Pot): F[Pot] = ??? | |
type DurationState[F[_]] = Stateful[F, FiniteDuration] | |
def waitUntilBoil[F[_]: DurationState](heatedPot: Pot): F[Unit] = ??? | |
def makeCoffee[F[_]: DurationState](pot: Pot): F[Coffee] = { | |
for { | |
withCoffeePwd <- addCoffeePowder(pot) | |
withWater <- addWater(withCoffeePwd) | |
heatedPot <- turnOnHeat(withWater) | |
_ <- waitUntilBoil(heatedPot) // compiles without addWater and addCoffeePowder knowing anything about State | |
coffee <- pot.pourCoffee | |
} yield coffee | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment