Last active
January 14, 2022 15:36
-
-
Save MateuszKubuszok/1f68adf47c85ea46ab702f6e8caad8c2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://scastie.scala-lang.org/G37skdDnS9maycTAhl5sRw