Skip to content

Latest commit

 

History

History
55 lines (32 loc) · 892 Bytes

README.md

File metadata and controls

55 lines (32 loc) · 892 Bytes

Automatic type class derivation in Scala 2 and Scala 3

Scala 2

    import core.Schema
    import core.Header._

    case class Foo(a: Int, c: String)

    val fields: List[String] = fieldNames[Foo]

    assert(fields == List("a", "c"))


    val list: List[String]   = List("1", "foo")

    val p: Map[String, String] = fields.zip(list).toMap // Map(a -> 1, c -> foo)
    val schema                 = Schema.of[Foo]

    assert(schema.readFrom(p) == Right(Foo(1, "foo")))
    cd scala2
    sbt test

Scala 3

    import core.list2class
    import core.Header.fieldNames

    case class Foo(a: Int, c: String)

    val fields: List[String] = fieldNames[Foo]

    assert(fields == List("a", "c"))


    val list: List[String] = List("1", "foo")

    assert(list2class[Foo](list) == Right(Foo(1, "foo")))
    cd scala3
    sbt test