Skip to content

Instantly share code, notes, and snippets.

@Fristi
Last active May 5, 2026 14:35
Show Gist options
  • Select an option

  • Save Fristi/e0d7a0c4a39bc1867d2c6148bac0725e to your computer and use it in GitHub Desktop.

Select an option

Save Fristi/e0d7a0c4a39bc1867d2c6148bac0725e to your computer and use it in GitHub Desktop.
ProfunctorK just because you can
import cats.*
trait Algebra[F[_], G[_]] {
def apply[A](fa: F[A]): G[A]
}
trait ProfunctorK[Alg[_[_], _[_]]]:
def lmapK[A[_], B[_], C[_]](s: Alg[A, C])(f: B ~> A): Alg[B, C] =
dimapK(s)(f)(FunctionK.id)
def rmapK[A[_], B[_], C[_]](s: Alg[A, C])(g: C ~> D): Alg[A, D] =
dimapK(s)(FunctionK.id)(g)
def dimapK[A[_], B[_], C[_], D[_]](s: Alg[A, C])(f: B ~> A)(g: C ~> D): Alg[B, D]
object ProfunctorK:
val algebra: ProfunctorK[Algebra] = new ProfunctorK[Algebra] {
override def dimapK[A[_], B[_], C[_], D[_]](s: Algebra[A, C])(f: B ~> A)(g: C ~> D): Algebra[B, D] = new Algebra[B, D] {
override def apply[X](fa: B[X]): D[X] =
g(s(f(fa)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment