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

.value might become more useful when one side is Never #3

Open
KyNorthstar opened this issue Oct 11, 2024 · 0 comments
Open

.value might become more useful when one side is Never #3

KyNorthstar opened this issue Oct 11, 2024 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@KyNorthstar
Copy link
Contributor

If one side is Never, then the value will never be that side, so .value could always return the other.
If both sides are Never, then .value would then naturally return Never, which fits in perfectly.

it could be implemented like this:

public extension Either where Left == Never {
    var value: Right {
        switch self {
        case .left: preconditionFailure("`Never` should not be reachable")
        case .right(let right): return right
        }
    }
}

public extension Either where Right == Never {
    var value: Left {
        switch self {
        case .right: preconditionFailure("`Never` should not be reachable")
        case .left(let left): return left
        }
    }
}
@KyNorthstar KyNorthstar added enhancement New feature or request good first issue Good for newcomers labels Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant