Two things that make code harder to reason about are exceptions and null
. The libraries in this repository aim to do something about exceptions by providing "result" structs to explicitly represent what happened during an operation that could potentially fail. To address null
, these results don't accept null
as any sort of input and don't provide null
from any output***.
There are three types of results:
Result
- For operations that can fail and do not have a return value.
- Can be either:
Success
, orFail
with a non-nullError
object.
Result<T>
- For operations that can fail and have a return value which is always provided.
- Can be either:
Success
with a non-null value, orFail
with a non-nullError
object.
Maybe<T>
- For operations that can fail and have a return value which may or may not be provided.
- Can be one of:
Success
with a non-null value,Fail
with a non-nullError
object, orNone
indicating no value.
There are a number of libraries in this repository: the main library, and several that depend on the main library and provide result functionality in specific domains.
The main library. Implementations of the Result monad.
Using RandomSkunk.Results from AspNetCore apps.
Using RandomSkunk.Results with Dapper.
Using RandomSkunk.Results with System.Net.Http and System.Net.Http.Json.
The solution in this repository contains an example Blazor Web Assembly app that demonstrates how to use the RandomSkunk.Result libraries. To run the app, select the ExampleBlazorApp.Server
project as the startup project.
These are the interesting parts of the example app (with links to the code):
- ExampleBlazorApp.Client project
- Typed HTTP Clients - each one uses RandomSkunk.Results.Http to make HTTP requests to the server
- WeatherForcastClient
- WeatherProfileClient
- Razor pages - each one uses one of the typed HTTP clients to make a request to the server, then handles the result
- FiveDayForecast
- WeatherProfiles
- Typed HTTP Clients - each one uses RandomSkunk.Results.Http to make HTTP requests to the server
- ExampleBlazorApp.Server project
- WeatherRepository - uses RandomSkunk.Results.Dapper to make queries to the database
- WeatherForecastSimulator - uses WeatherRepository to make queries to the database
- Controllers
- WeatherForecastController - uses WeatherForecastSimulator to simulate weather forecasts
- WeatherProfilesController - uses WeatherRepository to make queries to the database