Skip to content

Instantly share code, notes, and snippets.

@fserra-mdsol
Created October 4, 2022 20:26
Show Gist options
  • Save fserra-mdsol/b41e1b42736b964cf6430157724585e0 to your computer and use it in GitHub Desktop.
Save fserra-mdsol/b41e1b42736b964cf6430157724585e0 to your computer and use it in GitHub Desktop.
//> using lib "co.fs2::fs2-core:3.2.4"
//> using lib "org.typelevel::cats-effect:3.3.1"
import cats.effect.{ExitCode, IO, IOApp}
import fs2._
object FunctionalStreams extends IOApp {
def run(args: List[String]): IO[ExitCode] = (for {
_ <- IO.pure("a")
_ <- IO.println("Here")
s = (for {
_ <- Stream.emit[IO,Int](1)
_ <- Stream.empty
} yield ()).compile
_ <- if (args.nonEmpty) s.lastOrError else s.lastOrError.start
_ <- IO.println("Look ma, I skipped the Exception!")
} yield ()).handleErrorWith(e => IO.println(s"I just recovered from ${e.getClass}"))
.as(ExitCode.Success)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment