You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
?Result<int, string>.Error("Cannot divide by zero")
49
51
:Result<int, string>.Ok(numerator/denominator);
@@ -56,13 +58,16 @@ TryDivide(10, 2)
56
58
57
59
## Option
58
60
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.
60
62
61
63
### Creating Options
62
64
63
65
```csharp
64
66
varoption=Option<int>.Some(5);
65
67
68
+
// or, with type inference
69
+
varoptionInferred=Option.Some(5);
70
+
66
71
// or, with no value
67
72
varoptionNone=Option<int>.None();
68
73
@@ -72,7 +77,7 @@ var optionNull = Option<object>.Some(default!);
72
77
73
78
### Using Option
74
79
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.
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.
Result<int, string>.Ok(99)); // useful if creating the value is expensive
190
198
```
191
199
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.
@@ -251,6 +268,10 @@ Danom is integrated with [ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/
251
268
252
269
Documentation can be found [here](src/Danom.Mvc/README.md).
253
270
271
+
### ASP.NET Core Minimal API Integration
272
+
273
+
> Coming soon
274
+
254
275
## Contribute
255
276
256
277
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