johnhungerford / generic-schema

2 stars 1 forks source link

Recursive schema translation #75

Closed johnhungerford closed 2 years ago

johnhungerford commented 2 years ago

In translation, it is not practical to defer resolution of recursed translators, so we need another way of deriving translation. Here's my proposed solution:

trait RecursiveSchemaTranslator[T, S, OtherSchema[T], Trans <: Tuple] {
  def translate(schema: Schema.Aux[T, S], trans: Trans) : OtherSchema[T]
}

where Trans is a tuple of Function0[RecursiveSchemaTranslator[X, Y, OtherSchema[T]]. The implicit resolution of RecursiveSchemaTranslator will prepend thunked translators as it iterates through the subcomponents of a schema, and extractors/injectors for any LazyField encountered will look through the Trans tuple for a translator and will use that rather than continuing to derive one.

johnhungerford commented 2 years ago

closed with #84