Skip to content

Instantly share code, notes, and snippets.

@ivan-klass
Last active April 2, 2021 20:13
Show Gist options
  • Save ivan-klass/0b61a616749babdde7425c8fc808153c to your computer and use it in GitHub Desktop.
Save ivan-klass/0b61a616749babdde7425c8fc808153c to your computer and use it in GitHub Desktop.
Using cats.tagless for mocking TF-algebras
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