From 4673c281dec753c046e6ad33576079bc74b921af Mon Sep 17 00:00:00 2001 From: danicheg Date: Tue, 28 Dec 2021 21:55:43 +0300 Subject: [PATCH] Make a more meaty example of the syntax --- README.md | 5 +++-- docs/src/main/mdoc/index.md | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 991b00dc..e23e9773 100644 --- a/README.md +++ b/README.md @@ -62,12 +62,13 @@ It's possible to use interpolated syntax for logging. Currently, supported ops are: `trace`, `debug`, `info`, `warn`, `error`. You can use it for your custom `Logger` as well as for Slf4j `Logger`. -```scala mdoc +```scala +import cats.Applicative import cats.effect.Sync import org.typelevel.log4cats.Logger import org.typelevel.log4cats.syntax._ -def successComputation[F[_]: Sync]: F[Int] = Sync[F].pure(1) +def successComputation[F[_]: Applicative]: F[Int] = Applicative[F].pure(1) def errorComputation[F[_]: Sync]: F[Unit] = Sync[F].raiseError[Unit](new Throwable("Sorry!")) def log[F[_]: Sync: Logger] = diff --git a/docs/src/main/mdoc/index.md b/docs/src/main/mdoc/index.md index f5c36a67..9a6c1827 100644 --- a/docs/src/main/mdoc/index.md +++ b/docs/src/main/mdoc/index.md @@ -67,17 +67,20 @@ Currently, supported ops are: `trace`, `debug`, `info`, `warn`, `error`. You can use it for your custom `Logger` as well as for Slf4j `Logger`. ```scala mdoc +import cats.Applicative import cats.effect.Sync import org.typelevel.log4cats.Logger import org.typelevel.log4cats.syntax._ -def successComputation[F[_]: Sync]: F[Int] = Sync[F].pure(1) +def successComputation[F[_]: Applicative]: F[Int] = Applicative[F].pure(1) def errorComputation[F[_]: Sync]: F[Unit] = Sync[F].raiseError[Unit](new Throwable("Sorry!")) def log[F[_]: Sync: Logger] = for { result1 <- successComputation[F] _ <- info"First result is $result1" - _ <- errorComputation[F].onError(_ => error"We got an error!") + _ <- errorComputation[F].onError { + case _ => error"We got an error!" + } } yield () ``` \ No newline at end of file