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

Monad support #3

Closed
domn1995 opened this issue Jun 13, 2022 · 1 comment
Closed

Monad support #3

domn1995 opened this issue Jun 13, 2022 · 1 comment

Comments

@domn1995
Copy link
Owner

domn1995 commented Jun 13, 2022

As a developer, I want to use this library to generate monads, so that I don't have to write them manually.

I should be able to do something like this:

[Union]
public partial record Option<T>
{
    partial record Some(T Value);
    partial record None();
}

var option = new Option<string>.Some("foo");

var value = option.Match(
    some => some.Value,
    none => ""
);

Console.WriteLine(value); // "foo"
[Union]
public partial record Result<TFailure, TSuccess>
{
    partial record Success(TSuccess Value);
    partial record Failure(TFailure Error);
}

var result = new Result<Exception, string>.Failure(new Exception("Boom!"));
var message = result.Match(
    success => success.Value,
    failure => failure.Error.Message
);

Console.WriteLine(message); // "Boom!"
@domn1995
Copy link
Owner Author

Closed by #24 and #25

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