Created
February 7, 2017 19:33
-
-
Save emilypi/c265df205e60fca567d9791b6086f62f to your computer and use it in GitHub Desktop.
Generating fully qualified class instance from Tagged Union types with an associated Generator
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
| trait Instantiator[+A] { | |
| def apply(): A | |
| } | |
| object Instantiator { | |
| def apply[A](create: => A): Instantiator[A] = new Instantiator[A] { | |
| def apply(): A = create | |
| } | |
| } | |
| class U | |
| object U { | |
| implicit val instantiator: Instantiator[U] = Instantiator { new U } | |
| } | |
| class T | |
| type Tagged[U] = { type Tag = U } | |
| type @@[T, U] = T with Tagged[U] | |
| def gen[V: Instantiator]: V = implicitly[Instantiator[V]].apply() | |
| gen[(T @@ U)#Tag] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment