Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple-type derivation aliases #133

Closed
ivan-klass opened this issue May 20, 2020 · 2 comments
Closed

Add support for multiple-type derivation aliases #133

ivan-klass opened this issue May 20, 2020 · 2 comments

Comments

@ivan-klass
Copy link

It would be good to have an ability to alias mutliple derivations at once, so instead of etc

import com.sksamuel.avro4s.{Encoder, Decoder, SchemaFor}

@derive(Encoder, Decoder, SchemaFor)
case class FooBar(foo: String, bar: Int)

one can write (preferred)

@avro4sCodec
case class FooBar(foo: String, bar: Int)

or

@derive(avro4sCodec)
case class FooBar(foo: String, bar: Int)
@ivan-klass
Copy link
Author

Some thoughts:

For example, the alias could be implemented as

import derevo.MultipleAlias
class avro4sCodec extends MultipleAlias(Encoder, Decoder, SchemaFor)

or with type-builders like shapeless HList but for HK:

sealed trait Many[T <: Many[_]]
trait T extends Many[Nothing]
case class ::[A[_], Tail <: Many[_]]() extends Many[Tail]

class deriveMany[T <: Many[_]]() extends scala.annotation.Annotation

object example {
  type TypeClasses = List :: Option :: Vector :: T
  class alias extends deriveMany[example.TypeClasses]
}

// all forms are valid
@example.alias
@deriveMany[example.TypeClasses]
@deriveMany[Either[String, *] :: Function[*, Int] :: T]
case class FooBar(int: Int, str: String)


println("compiles")

the latter compiles at scastie

@zawodskoj
Copy link
Collaborator

Implemented in #333

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants