Skip to content

Instantly share code, notes, and snippets.

@ghostdogpr
Created September 29, 2019 09:44
Show Gist options
  • Save ghostdogpr/0dcc6e87df86a3a476f8b6f6674b4c92 to your computer and use it in GitHub Desktop.
Save ghostdogpr/0dcc6e87df86a3a476f8b6f6674b4c92 to your computer and use it in GitHub Desktop.
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