Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import $ivy.`com.chuusai::shapeless:2.3.3`
- import shapeless._
- trait Fields[T] {
- def fields: List[String]
- override def toString: String = fields.mkString(", ")
- }
- object Fields extends LabelledProductTypeClassCompanion[Fields] {
- def apply[T](fs: List[String]): Fields[T] = new Fields[T] {
- override def fields: List[String] = fs
- }
- implicit val string: Fields[String] = apply[String](Nil)
- implicit def anyVal[T <: AnyVal]: Fields[T] = apply[T](Nil)
- object typeClass extends LabelledProductTypeClass[Fields] {
- override def product[H, T <: HList](name: String, ch: Fields[H], ct: Fields[T]) : Fields[H :: T] =
- Fields(name :: ct.fields)
- override def emptyProduct : Fields[HNil] = Fields(Nil)
- override def project[F, G](instance: => Fields[G], to: F => G, from: G => F) = Fields(instance.fields)
- }
- }
- case class Foo(bar: String, baz: Boolean)
- println(implicitly[Fields[Foo]].fields)
Add Comment
Please, Sign In to add comment