I'm pretty new to shapeless so the question might be easy.
Here is the ADT:
sealed trait Test
final case class A() extends Test
final case class B() extends Test
final case class C() extends Test
...
final case class Z() extends Test
Is it possible to write a function without extremely cumbersome pattern matching?
def split(lst: List[Test]): List[A] :: List[B] :: ... :: HNil = //
At compile time all elements of
Listhave the same static typeTest, so there is no way to distinguish elementsA,B,C... using compile-time technique only (Shapeless, type classes, implicits, macros, compile-time reflection). The elements are distinguishable at runtime only, so you have to use some runtime technique (pattern matching, casting, runtime reflection).Why Does This Type Constraint Fail for List[Seq[AnyVal or String]]
Scala: verify class parameter is not instanceOf a trait at compile time
flatMap with Shapeless yield FlatMapper not found
Try
splitinto a Map using runtime reflectionor
splitinto aHListusing Shapeless + runtime reflectionTesting:
Scala 3 collection partitioning with subtypes (Scala 2/3)