-
Notifications
You must be signed in to change notification settings - Fork 42
Cats Effect Support
Matt Hicks edited this page Feb 6, 2022
·
1 revision
libraryDependencies += "com.outr" %% "scribe-cats" % scribeVersion
There are many ways you can leverage the cats module for Scribe. It is intentionally very flexible to allow for many use-cases. The goal of this module is to abstract the side-effects of Scribe into a F[_]
return.
The simplest scenario is to use the convenience reference to leverage the IO
type:
scribe.cats.io.info("Hello, World!") // Returns IO[Unit]
For greater flexibility, you can do ad-hoc calls to use an arbitrary type. For the purposes of this example, we'll just use IO
:
scribe.cats[IO].info("Hello, World!") // Returns IO[Unit]
You can also create the reference ahead of time to avoid requiring the implicit Sync[F]
during calls:
val logger = scribe.cats[IO]
logger.info("Hello, World!") // Returns IO[Unit]
If you are mixing uses or have a more specific controlled scenario you want to handle, you take a Logger
instance and use it through the cats module:
import scribe.cats._
val logger = Logger("MyLogger")
logger.f[IO].info("Hello, World!") // Returns IO[Unit]
A much more complex scenario:
class Biz[F[_]: MonadThrow: Scribe] {
def doStuff(): F[String] = for {
_ <- Scribe[F].info("Hello, World!") // Returns IO[Unit]
} yield {
"done"
}
}
val biz = new Biz[IO]
biz.doStuff()