Converts monad types from LanguageExt to AspNet Core Result types
$ dotnet add package Genesis.LanguageExt.AspNetCoreConverts LanguageExt monads to ActionResult or minimal API IResult.
200 OK with a response bodyUnit will return a success code of 204 No ContentOption<T> monad will either be a success of 200 or 204 and the none condition is converted to a 404 Not Found
Option<T> such as Fin<Option<T>> could return 200, 204, 404, or 500 as Fin<Option<T>> could be a success with an option of
Unit (204)T (200)None (404)Error (500).Try monad will return either a 200, 204, or 500TryOption monad will return either a 200, 204, 404, or 500Eff monad will return a 200, 204, or 500Aff monad will return a 200, 204, or 500Proper IEFT problem detail responses will be presented with the appropriate
status code based on the exception that is contained within the Fin, Try, TryOption, Eff, and Aff monads.
LanguageExt monads can be converted to Action or IResult. The extensions functions can be used by importing Genesis.
using Genesis;
//. Other code
IResult result = Try(() => "Hello, World!").ToResult();using static LanguageExt.Prelude;
using Genesis;
interface IService { Option<string> GetMessage(); }
class MyService : IService {
Option<string> GetMessage() => "Hello, World!";
}
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddTransient<IService, MyService>();
var app = builder.Build();
app.MapGet("/", (IService service) => service.GetMessage().ToResult());
app.Run();