Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
type ~>[F[_], G[_]] = [A] => F[A] => G[A]
final case class <~>[F[_], G[_]](to: F ~> G, from: G ~> F):
val mapAsTo: [A, B] => (G[A] => G[B]) => (F[A] => F[B]) =
[A, B] => (f: (G[A] => G[B])) => to[A].andThen(f).andThen(from[B])
val mapAsFrom: [A, B] => (F[A] => F[B]) => (G[A] => G[B]) =
[A, B] => (f: (F[A] => F[B])) => from[A].andThen(f).andThen(to[B])
extension [F[_], A](fa: F[A])
transparent inline def mapAs[G[_]]: [B] => (G[A] => G[B]) => F[B] =
scala.compiletime.summonFrom {
case biK: (F <~> G) => [B] => (f: (G[A] => G[B])) => biK.mapAsTo[A, B](f)(fa)
case biK: (G <~> F) => [B] => (f: (G[A] => G[B])) => biK.mapAsFrom[A, B](f)(fa)
}
// idea: (fa: F[A]).mapAs[G] { ga => g... : G[B] } : F[B]
@MateuszKubuszok
Copy link
Author

MateuszKubuszok commented Jan 14, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment