scala-hamsters / hamsters

A mini Scala utility library
Apache License 2.0
291 stars 23 forks source link

Case class <-> HList conversions #83

Closed oraclewalid closed 6 years ago

oraclewalid commented 6 years ago

Case class <-> HList conversions

dgouyette commented 6 years ago

Great work @oraclewalid

Would it be easy to keep field name ? (would be helpul for json reader/writer) GenSpec should be in the same package than other tests : io.github.hamsters

It doens't work on deep classes : exemple with this tests

  @GenMacro
  case class Location(lat : Long, longitude : Long)

  @GenMacro
  case class DeepPerson(name: String, age :Int, weight :Option[Int] = None, location: Location)

  "deep class" should " generate toClass and toHList to" in {
    val p = DeepPerson(name = "Christophe Colomb", age = 42, location = Location(42, 54))

    HList.toHList(p)  shouldEqual "Christophe Colomb"::42::None :: (42 :: 54 :: HNil) ::HNil

  }
oraclewalid commented 6 years ago

@dgouyette