Skip to content

Commit fc56fa8

Browse files
committed
readme
1 parent 8c94cc1 commit fc56fa8

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

README.md

+37-16
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ Danom is a C# library that provides (monadic) structures to facilitate durable p
1212
- Integrated with [ASP.NET Core](#aspnet-core-mvc-integration) and [Fluent Validation](#fluent-validation-integration).
1313

1414
## Design Goals
15-
- **Simplicity**: Easy to use API for common monadic operations.
16-
- **Performance**: Efficient implementation to minimize overhead.
17-
- **Interoperability**: Seamless integration with existing C# code and libraries.
18-
- **Durability**: Prevent direct use of internal value, enforcing exhaustive matching.
15+
- Easy to use API for common monadic operations.
16+
- Efficient implementation to minimize overhead.
17+
- Seamless integration with existing C# code and libraries.
18+
- Prevent direct use of internal value, enforcing exhaustive matching.
1919

2020
## Getting Started
2121

@@ -35,15 +35,17 @@ dotnet add package Danom
3535
```csharp
3636
using Danom;
3737

38-
// Create an Option
38+
// Working with Option type
3939
var option = Option<int>.Some(5);
4040

4141
option.Match(
4242
some: x => Console.WriteLine("Value: {0}", x),
4343
none: () => Console.WriteLine("No value"));
4444

45-
// Create a Result
46-
public Result<int, string> TryDivide(int numerator, int denominator) =>
45+
// Working with Result type
46+
public Result<int, string> TryDivide(
47+
int numerator,
48+
int denominator) =>
4749
denominator == 0
4850
? Result<int, string>.Error("Cannot divide by zero")
4951
: Result<int, string>.Ok(numerator / denominator);
@@ -56,13 +58,16 @@ TryDivide(10, 2)
5658

5759
## Option
5860

59-
Represents when an actual value might not exist for a value or named variable. An option has an underlying type and can hold a value of that type, or it might not have a value. Options are a fantastic means of reducing primitive congestion in your code, and they are a much safer way to handle null values and virutally eliminate null reference exceptions.
61+
Options have an underlying type and can "optionallu" hold a value of that type. Options are a much safer way to handle nullable values, they virtually eliminate null reference exceptions, and a fantastic means of reducing primitive congestion in your code.
6062

6163
### Creating Options
6264

6365
```csharp
6466
var option = Option<int>.Some(5);
6567

68+
// or, with type inference
69+
var optionInferred = Option.Some(5);
70+
6671
// or, with no value
6772
var optionNone = Option<int>.None();
6873

@@ -72,7 +77,7 @@ var optionNull = Option<object>.Some(default!);
7277

7378
### Using Option
7479

75-
Options are commonly used when a operation might not return a value. For example:
80+
Options are commonly used when a operation might not return a value. For example, the method below tries to find a number in a list that satisfies a predicate. If the number is found, it is returned as a `Some`, otherwise, `None` is returned.
7681

7782
```csharp
7883
public Option<int> TryFind(IEnumerable<int> numbers, Func<int, bool> predicate) =>
@@ -122,24 +127,27 @@ Option<int> optionOrElseWith =
122127

123128
## Result
124129

125-
Represents the result of an operation that can either succeed or fail. These results can be chained together allowing you to form error-tolerant pipelines. This lets you break up functionality like this into small pieces which are as composable as you need them to be. Also benefiting from the exhaustive matching.
130+
Results are used to represent a success or failure outcome. They provide a more concrete way to manage the expected errors of an operation, then throwing exceptions. Especially in recoverable or reportable scenarios.
126131

127132
### Creating Results
128133

129134
```csharp
130135
var result = Result<int, string>.Ok(5);
136+
131137
// or, with an error
132138
var resultError = Result<int, string>.Error("An error occurred");
139+
133140
// or, using the built-in Error type
134141
var resultErrors = Result<int>.Ok(5);
142+
135143
var resultErrorsError = Result<int>.Error("An error occurred");
136144
var resultErrorsMultiError = Result<int>.Error(["An error occurred", "Another error occurred"]);
137145
var resultErrorsTyped = Result<int>.Error(new ResultErrors("error-key", "An error occurred"));
138146
```
139147

140148
### Using Results
141149

142-
Results are commonly used when an operation might not succeed, and you want to manage the _expected_ errors. For example:
150+
Results are commonly used when an operation might not succeed, and you want to manage or report back the _expected_ errors. For example:
143151

144152
```csharp
145153
public Result<int, string> TryDivide(int numerator, int denominator) =>
@@ -189,13 +197,20 @@ Result<int, string> resultOrElseWith =
189197
Result<int, string>.Ok(99)); // useful if creating the value is expensive
190198
```
191199

192-
Since error messages are frequently represented as string collections, often with keys (e.g., for validation), the `ResultErrors` type is provided to simplify Result creation. The flexible constructor allows errors to be initialized with a single string, a collection of strings, or a key-value pair.
200+
Since error messages are frequently represented as keyed string collections, the `ResultErrors` type is provided to simplify Result creation. The flexible constructor allows errors to be initialized with a single string, a collection of strings, or a key-value pair.
193201

194202
```csharp
195-
Result<int, ResultErrors> resultErrors = Result<int>.Ok(5);
196-
Result<int, ResultErrors> resultErrorsError = Result<int>.Error("An error occurred");
197-
Result<int, ResultErrors> resultErrorsMultiError = Result<int>.Error(["An error occurred", "Another error occurred"]);
198-
Result<int, ResultErrors> resultErrorsTyped = Result<int>.Error(new ResultErrors("error-key", "An error occurred"));
203+
var resultErrors =
204+
Result<int>.Ok(5);
205+
206+
var resultErrorsError =
207+
Result<int>.Error("An error occurred");
208+
209+
var resultErrorsMultiError =
210+
Result<int>.Error(["An error occurred", "Another error occurred"]);
211+
212+
var resultErrorsTyped =
213+
Result<int>.Error(new ResultErrors("error-key", "An error occurred"));
199214
```
200215

201216
## ResultOption
@@ -206,8 +221,10 @@ Represents a combination of the Result and Option monads. This is useful when yo
206221

207222
```csharp
208223
var resultOption = ResultOption<int, string>.Ok(5);
224+
209225
// or, with an error
210226
var resultOptionError = ResultOption<int, string>.Error("An error occurred");
227+
211228
// or, with no value
212229
var resultOptionNone = ResultOption<int, string>.None();
213230
```
@@ -251,6 +268,10 @@ Danom is integrated with [ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/
251268

252269
Documentation can be found [here](src/Danom.Mvc/README.md).
253270

271+
### ASP.NET Core Minimal API Integration
272+
273+
> Coming soon
274+
254275
## Contribute
255276

256277
Thank you for considering contributing to Danom, and to those who have already contributed! We appreciate (and actively resolve) PRs of all shapes and sizes.

0 commit comments

Comments
 (0)