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

Return "partial" OneOf types #181

Open
juantxorena opened this issue Sep 26, 2024 · 0 comments
Open

Return "partial" OneOf types #181

juantxorena opened this issue Sep 26, 2024 · 0 comments

Comments

@juantxorena
Copy link

I'm liking this library, but I've found a situation which IMHO is a bit annoying and doesn't really make sense. Consider this code:

public async Task<OneOf<None, Unknown, False>> DoThings(Object input)
{
    if (something)
    {
        return new False();
    }
    OneOf<None, Unknown> result = await OtherMethod(input);
    return result;
}

It fails to compile, because it cannot convert from OneOf<None, Unknown> to OneOf<None, Unknown, False>. It makes sense, but considering that I'm returning a False, or a None or Unknown, I think it should work. Instead, I have to manually match the output and return the types, like this, which is pretty redundant:

public async Task<OneOf<None, Unknown, False>> DoThings(Object input)
{
    if (something)
    {
        return new False();
    }
    OneOf<None, Unknown> result = await OtherMethod(input);
    return result.Match<OneOf<None, Unknown, False>>(
	none => new None(),
	unknown => new Unknown()
    );
}

Maybe it's difficult to implement, but IMHO it makes sense that it should work.

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