mdedetrich commented on PR #160:
URL: 
https://github.com/apache/incubator-pekko-connectors/pull/160#issuecomment-1685880588

   So I managed to make some decent progress, I figured out the biggest issue I 
was having before is not having a type level data structure to represent the 
field's/types of a case class. With shapeless there is a `FieldType` however 
there didn't seem to be an equivalent for Scala 3's inbuild generics.
   
   Thankfully I came across 
https://scalac.io/blog/inline-your-boilerplate-harnessing-scala3-metaprogramming-without-macros/
 which provided the exact data structure needed, i.e.
   
   ```scala
   import scala.compiletime.*
   import scala.deriving.*
   sealed trait Field[Label <: String, Type]
   
   object Field {
     type FromLabelsAndTypes[Labels <: Tuple, Types <: Tuple] <: Tuple =
       (Labels, Types) match {
         case (EmptyTuple, EmptyTuple) => EmptyTuple
         case (labelHead *: labelTail, typeHead *: typeTail) =>
           Field[labelHead, typeHead] *: FromLabelsAndTypes[labelTail, typeTail]
       }
   }
   ```
   
   You can then create this type level data structure using a mirror, i.e.
   
   ```scala
   case class Test(string: String, int: Int)
   
   val mirror = summon[Mirror.ProductOf[Test]]
   
   type Fields = FromLabelsAndTypes[mirror.MirroredElemLabels, 
mirror.MirroredElemTypes]
   // defined alias type Fields = (Field["string", String], Field["int", Int])
   ```
   
   Which is actually whats needed, i.e a type with each element being a `Field` 
that contains the case class fieldname on the left and the case class type on 
the right.
   
   The PR isn't completely done but this a big step. Pinging @jrudolph because 
you showed interest before.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to