Skip to content

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

@KyNorthstar

Description

@KyNorthstar

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
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions