Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider codecs of union types #303

Open
mpilquist opened this issue Feb 27, 2021 · 0 comments
Open

Consider codecs of union types #303

mpilquist opened this issue Feb 27, 2021 · 0 comments

Comments

@mpilquist
Copy link
Contributor

mpilquist commented Feb 27, 2021

// On Codec[A]:
  final def |[B](that: Codec[B])(using reflect.Typeable[A], reflect.Typeable[B]): Codec[A | B] = new Codec[A | B]:
    def sizeBound = sizeBound | that.sizeBound
    def encode(ab: A | B) = ab match
      case a: A => self.encode(a)
      case b: B => that.encode(b)
    def decode(bv: BitVector) =
      self.decode(bv).orElse(that.decode(bv))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant