Skip to content

gekomad/automatic-type-class-derivation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Languages