zio-schema icon indicating copy to clipboard operation
zio-schema copied to clipboard

Split Schema into covariant and contravariant parts

Open jdegoes opened this issue 3 years ago • 0 comments

In some cases, it is enough to be able to tear down an A into its pieces, or build an A from its pieces, but the ability to do both is not needed, and imposing that ability onto a type leads to excessive pain for library authors.

To make this easier, we can have:

sealed trait SchemaDeconstruct[-A] {
  // Contravariant part of `Schema`
}
sealed trait SchemaConstruct[+A] {
  // Covariant part of `Schema`
}
final case class Schema[A](deconstruct: SchemaDeconstruct[A], construct: SchemaConstruct[A]) {
  // Existing methods on Schema...
}
object Schema {
  // Existing implicits for Schema...
  implicit ...
}

jdegoes avatar Feb 18 '22 11:02 jdegoes