spartanz / schemaz

A purely-functional library for defining type-safe schemas for algebraic data types, providing free generators, SQL queries, JSON codecs, binary codecs, and migration from this schema definition
https://spartanz.github.io/schemaz
Apache License 2.0
164 stars 18 forks source link

Generic derivation of "Isos" #47

Open vil1 opened 5 years ago

vil1 commented 5 years ago

From the user's point of view, the most tedious part of defining a schema is writing the values of the iso field of unions and records.

For instance, in ordre to define the schema for a class

final case class Foo(i: Int, l: Long, s: String, b: Boolean)

one must implement an Iso[(Int, (Long, (String, (Boolean)))), Foo], which is 100% boilerplate.

Using generic programming, it is possible to derive automatically at compile time an Iso between any case class (product type) and its "nested tuples" representation. We should provide such a way in the generic module using scalaz-deriving.

This issue must be solved without modifying the existing API for building schemas (namely, the public methods in SchemaModule).

An acceptable solution would be to define some Generic* module extending SchemaModule with two methods :

Important note

This issue should be solved while taking into account the results of #44.

*: these names are merely suggested names