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

Question: How to use linq query syntax for Result types #566

Open
christophercalm opened this issue Sep 17, 2024 · 0 comments
Open

Question: How to use linq query syntax for Result types #566

christophercalm opened this issue Sep 17, 2024 · 0 comments

Comments

@christophercalm
Copy link

Is the Select method not supported for linq query syntax for result?

As an example here is code that works with Maybe

Maybe<string> name = "John";

var upper = from x in name select x.ToUpper();`

But does not work with Result

This is the error:
CS1936 Could not find an implementation of the query pattern for source type 'Result'. 'Select' not found.

I see the that SelectMany operation is supported but it looks like there is no select. Is this something that you would be open to me adding?

It would help with workflows like this

Result<string> GetGreetingMessage(string userName)
{
    var maybeGreeting =
        from name in ValidateName(userName)   // Bind the validated name
        select CreateGreetingMessage(name);   // Map to a greeting message

    // Convert Maybe to Result
    return maybeGreeting.ToResult("Invalid name provided");
}

Maybe<string> ValidateName(string name)
{
    // Check if the name is valid, return Maybe.None if invalid
    return string.IsNullOrWhiteSpace(name) ? Maybe<string>.None : Maybe<string>.From(name);
}

but for results.

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