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
sealed trait Tree
final case class Node(left: Tree, right: Tree) extends Tree
final case class Leaf(label: Int) extends Tree
One idea (thx @julienrf) would be to have a dedicated member in the GADT for that:
final class SchemaReference[F[_], A](ref: => F[A]) extends Schema[F, A]
which would allow us to use lazy vals or def to build such recursive schema, but would require interpreters implementers (that is us, most of the time) to properly handle the laziness.
lazy val tree = union(
"Node" -+>: record(
"left" -*>: tree :*:
"right" -*>: tree
) :+:
"Leaf" -+>: record(
"label" -*>: prim(IntSchema)
)
)
Another, more "essential" way would be to find a way to encode the "y-combinator", or some kind of fix-point, at the schema level.
We need a way to represent recursive types like:
One idea (thx @julienrf) would be to have a dedicated member in the GADT for that:
which would allow us to use
lazy val
s ordef
to build such recursive schema, but would require interpreters implementers (that is us, most of the time) to properly handle the laziness.Another, more "essential" way would be to find a way to encode the "y-combinator", or some kind of fix-point, at the schema level.