Skip to content

Return "partial" OneOf types #181

@juantxorena

Description

@juantxorena

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions