Created
June 13, 2023 12:30
-
-
Save cm-kazup0n/31f89e5792cdb4a801754437c713a148 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
//> using dep org.typelevel::cats-effect:2.5.5 | |
//> using dep com.lihaoyi::pprint:0.8.1 | |
import cats.effect._ | |
import cats.Monad | |
import cats.implicits._ | |
def findParitialQuote[F[_]: Sync]: F[String] = | |
Sync[F] | |
.delay(pprint.pprintln("All I kept thinking about, over and over, was...")) | |
.as("You can't live forever") | |
def completeQuote[F[_]: Monad](f: F[String]): F[String] = for { | |
s <- f | |
t = s + "; you can't live forever." | |
} yield t | |
import cats.effect.Sync | |
object main extends IOApp.Simple { | |
override def run: IO[Unit] = for { | |
q <- Async.memoize[IO, String](findParitialQuote) | |
fs <- List.range(0, 100).map(_ => completeQuote(q).start).sequence | |
_ <- fs.map(_.join).sequence | |
_ <- completeQuote(q).map(pprint.pprintln(_)) | |
} yield () | |
} | |
main.run.unsafeRunSync() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment