Last active
April 2, 2021 20:13
-
-
Save ivan-klass/0b61a616749babdde7425c8fc808153c to your computer and use it in GitHub Desktop.
Using cats.tagless for mocking TF-algebras
This file contains 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
import cats.{ApplicativeError, ~>} | |
import cats.tagless.FunctorK | |
object NotImplemented { | |
private def notImplemented[F[_]](implicit F: ApplicativeError[F, _ >: NotImplementedError]): F ~> F = | |
new (F ~> F){ | |
override def apply[A](fa: F[A]): F[A] = F.raiseError(new NotImplementedError()) | |
} | |
/* Replace all delayed impure operations with raising non-implemented error */ | |
def apply[TF[_[_]], F[_]](tf: TF[F])( | |
implicit F: ApplicativeError[F, _ >: NotImplementedError], | |
TF: FunctorK[TF] | |
): TF[F] = TF.mapK(tf)(notImplemented) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment