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

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

Open
anqit opened this issue Sep 11, 2024 · 8 comments · May be fixed by #3156
Open

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

anqit opened this issue Sep 11, 2024 · 8 comments · May be fixed by #3156
Labels
💎 Bounty enhancement New feature or request

Comments

@anqit
Copy link

anqit commented Sep 11, 2024

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 anqit added the enhancement New feature or request label Sep 11, 2024
@anqit
Copy link
Author

anqit commented Sep 11, 2024

Another place that comes to mind is using tuples and *: could simplify Combiner quite a bit. I'm guessing none of this is a new thought, so curious if there are plans for these sorts of updates?

@987Nabil
Copy link
Contributor

I was already planning for some Scala 3 extensions. I don't think I would change Alternator. Instead I would add Scala 3 specific operators. This is because you sometimes explicitly want either even in Scala 3. If the left hand and the right hand side have the same type for example. But I agree, that besides that a union based API would be nice.

Also, having for the same ops different return types in different Scala versions feels not so clean to me.
We already added something similar to zio schema.

@anqit
Copy link
Author

anqit commented Sep 11, 2024

Is there work started for this at all? I wouldn't mind taking a stab at pushing that over the finish line, feels like a good first ZIO contribution!

@jdegoes
Copy link
Member

jdegoes commented Sep 18, 2024

/bounty $450 for Scala 3-specific composition variants for any of the Endpoint methods that currently use Alternator or Combiner, together with accompanying Scala-3-specific test cases.

Copy link

algora-pbc bot commented Sep 18, 2024

💎 $450 bounty • ZIO

Steps to solve:

  1. Start working: Comment /attempt #3125 with your implementation plan
  2. Submit work: Create a pull request including /claim #3125 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to zio/zio-http!

Add a bountyShare on socials

Attempt Started (GMT+0) Solution
🟢 @987Nabil Sep 19, 2024, 1:34:40 AM #3156

@987Nabil
Copy link
Contributor

987Nabil commented Sep 19, 2024

/attempt #3125

Algora profile Completed bounties Tech Active attempts Options
@987Nabil    92 ZIO bounties
+ 4 bounties from 2 projects
Scala
Cancel attempt

987Nabil added a commit to 987Nabil/zio-http that referenced this issue Sep 19, 2024
@987Nabil 987Nabil linked a pull request Sep 19, 2024 that will close this issue
Copy link

algora-pbc bot commented Sep 19, 2024

💡 @987Nabil submitted a pull request that claims the bounty. You can visit your bounty board to reward.

987Nabil added a commit to 987Nabil/zio-http that referenced this issue Sep 20, 2024
@Kishan-Kulkarni
Copy link

Is this issue open, I would like to have a go at it if it's open.

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💎 Bounty enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants