Created
September 29, 2019 09:44
-
-
Save ghostdogpr/0dcc6e87df86a3a476f8b6f6674b4c92 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
import language.experimental.macros | |
import language.implicitConversions | |
import magnolia._ | |
trait MyTypeclass[T] { | |
def f(t: T): String | |
} | |
object MyTypeclass { | |
type Typeclass[T] = MyTypeclass[T] | |
implicit def deriveOption[A](implicit ev: Typeclass[A]): Typeclass[Option[A]] = (t: Option[A]) => ??? | |
def combine[T](ctx: CaseClass[Typeclass, T]): Typeclass[T] = (t: T) => ??? | |
def dispatch[T](ctx: SealedTrait[Typeclass, T]): Typeclass[T] = (t: T) => ??? | |
implicit def gen[T]: Typeclass[T] = macro Magnolia.gen[T] | |
} | |
object Test extends App { | |
case class SomeClass(id: Option[Another]) | |
case class Another(b: String) | |
MyTypeclass.gen[List[SomeClass]] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment