Amatsugu 31f122bba6
All checks were successful
.NET / build (push) Successful in 27s
Updated readme
2025-08-18 10:48:14 -04:00
2025-08-18 10:23:36 -04:00
2025-08-18 10:23:36 -04:00
2025-08-18 10:23:36 -04:00
2025-08-18 10:23:36 -04:00
2025-08-18 10:23:36 -04:00
2025-08-18 10:23:36 -04:00
2025-08-18 10:23:36 -04:00
2025-08-18 10:48:14 -04:00

MaybeError

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.


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.


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);

Description
No description provided
Readme MIT 67 KiB
Languages
C# 100%