Skip to content

Instantly share code, notes, and snippets.

@cm-kazup0n
Created June 13, 2023 12:30
Show Gist options
  • Save cm-kazup0n/31f89e5792cdb4a801754437c713a148 to your computer and use it in GitHub Desktop.
Save cm-kazup0n/31f89e5792cdb4a801754437c713a148 to your computer and use it in GitHub Desktop.
//> 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