Skip to content

Commit

Permalink
smaller implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Odomontois committed Mar 19, 2021
1 parent 164c8cb commit 0f47dd1
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import org.slf4j.helpers.MessageFormatter
import tofu.data._
import tofu.higherKind.derived.representableK
import tofu.optics.macros.Optics
import cats.tagless.syntax.functorK._

import LoggingMidSuite._
import tofu.syntax.funk

@derive(representableK, loggingMidTry)
trait Greeter[F[_]] {
Expand All @@ -18,11 +20,13 @@ trait Greeter[F[_]] {

object Greeter extends LoggingCompanion[Greeter] {
import LoggingMidSuite._
implicit object Instance extends Greeter[Eff] {
def setName(name: String): Eff[Unit] =
CalcM.set(Some(name)).focus(State.name).void
type SmalEff[+A] = ICalcM[Nothing, Any, Option[String], Throwable, A]

def hello: Eff[String] = CalcM.get[State].map(_.name).flatMap {
implicit object Instance extends Greeter[SmalEff] {
def setName(name: String): SmalEff[Unit] =
CalcM.set(Some(name)).void

def hello: SmalEff[String] = CalcM.get.flatMap {
case None => CalcM.raise(MissingName())
case Some(name) => CalcM.pure(s"Hello, $name")
}
Expand Down Expand Up @@ -50,7 +54,7 @@ object LoggingMidSuite {
}

class LoggingMidSuite extends AnyFunSuite {
val greeter: Greeter[Eff] = Greeter.Instance.attachErrLogs[Throwable]
val greeter: Greeter[Eff] = Greeter.Instance.mapK(funk.funK(_.focus(State.name))).attachErrLogs[Throwable]
val ErrName = classOf[MissingName].getName()
val GreeterName = classOf[Greeter[Any]].getName()

Expand Down

0 comments on commit 0f47dd1

Please sign in to comment.