zio / zio-schema

Compositional, type-safe schema definitions, which enable auto-derivation of codecs and migrations.
https://zio.dev/zio-schema
Apache License 2.0
141 stars 161 forks source link

Improve orElse, to auto widen for sum types and remove ClassTags #670

Closed 987Nabil closed 6 months ago

987Nabil commented 6 months ago

@jdegoes I realised, that for

enum Foo:
  case A, B

The current version would return Schema[A | B] for Schema[A].orElse(Schema[B]) but with this change it would return Schema[Foo]. Also the inline removes the need for class tags

vigoo commented 6 months ago

Does it still infer A | B if they are independent from each other, and not Any?

987Nabil commented 6 months ago

Yes, it does. This is the same technique used by Either#merge which works also well with Scala 3 union types. I actually think this is the only right design to have inferred super types that might be union types.