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

Update `Alternator` and perhaps others to include implicits for scala 3 type updates

Open anqit opened this issue 5 months ago • 8 comments

Is your feature request related to a problem? Please describe. I am trying to create an Endpoint with multiple output error possibilities, and was hoping the combined error type would end up being a union type, but it looks like the implicit Alternator being used results in Either being used instead. Alternator is sealed, so adding my own, while a simple implementation, is not possible.

Describe the solution you'd like I would like an Alternator instance that combines types using union types instead of nesting Eithers.

Describe alternatives you've considered None, just living with nested Eithers

Additional context should be as simple as:

    given unionAlternator[A, B]: Alternator.WithOut[A, B, A | B] =
        new Alternator[A, B]:
            type Out = A | B

            def left(l: A): Out = l

            def right(r: B): Out = r

            def unleft(out: Out): Option[A] = out match
                case a: A => Some(a)
                case _ => scala.None

            def unright(out: Out): Option[B] = out match
                case b: B => Some(b)
                case _ => scala.None

I'm wondering if there are other places where converting to union types over either's, or other scala 3 type updates in general, could be useful

anqit avatar Sep 11 '24 06:09 anqit