Created
October 4, 2022 20:26
-
-
Save fserra-mdsol/b41e1b42736b964cf6430157724585e0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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