-
-
Save mpilquist/6449193 to your computer and use it in GitHub Desktop.
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 shapeless._ | |
trait F[A] { | |
def xmap[B](f: A => B, g: B => A): F[B] | |
def as[B] = new AsAux[B] | |
class AsAux[B] { | |
def apply[C](implicit gen: Generic.Aux[B, C], ev: A =:= C): F[B] = | |
xmap(a => gen.from(ev(a)), b => gen.to(b).asInstanceOf[A]) | |
} | |
} | |
case class Bar(x: Int, y: String) | |
object Example { | |
val a: F[Int :: String :: HNil] = null | |
val b: F[Bar] = a.as[Bar].apply // TODO Get rid of need to call apply here | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment