Compare commits

..

2 Commits

Author SHA1 Message Date
31f122bba6 Updated readme
All checks were successful
.NET / build (push) Successful in 27s
2025-08-18 10:48:14 -04:00
4988103d32 Updated readme
All checks were successful
.NET / build (push) Successful in 24s
2025-08-18 10:44:22 -04:00

View File

@@ -1,2 +1,50 @@
# MaybeError
A simple library to allow "error as values" functionallity in C#
A simple library to allow "error as values" functionallity in C# inspired by the Result enum from rust.
# Usage
All you need to do is wrap you return in `Maybe` or `ValueMaybe` and you can leave most of your code unchanced. Return your normal types as is. When you have an error you can either return a caught exception or create a return a new error like below.
```csharp
public Maybe<string> SomeFunction(bool isGood)
{
if (isGood)
return "All good";
return new Error("This is not good");
}
```
Once you have a `Maybe<T>` you can inspect it's contents in several ways.
```csharp
var result = SomeFunction(true);
// Get the value with an optional default value if there is an error
var message = result.ValueOrDefault("Not good, but it's ok");
//The value is implicitly where possible, but will throw the error as an exception if there was one
string messageCast = result;
// You can also check if there was and error manually
if (result.HasError)
{
// do something
}
// Or for a value if you prefer
if (result.HasValue)
{
// do something
}
// You can access the error like this
if (result.HasError)
Console.WriteLine(result.Error);
```