diff --git a/README.md b/README.md index bcfd6ab..93de678 100644 --- a/README.md +++ b/README.md @@ -222,10 +222,32 @@ values and utilizing `Maybe` methods for chaining operations. > **Practical rule**: Use `Nullable` to model class attributes and `Maybe` to model return values and > method paramethers. -## Converting `Maybe` to `Result` +### Recovering from `Maybe.None` with `WithDefault` + +The `WithDefault` method allows recovering from a `Maybe.None` instance by providing a default value. + +For example, consider the following code snippet: + +```csharp +var maybeValue = Maybe.None(); +var value = maybeValue.WithDefault(42); +``` + +### Converting `Maybe` to `Result` It is common to implement a pipeline of operations where an empty `Maybe` instance should be interpreted as a failure, -in this case the `Maybe` instance can be converted to a `Result` instance by using the `ToResult` method. +in this case the `Maybe` instance can be converted to a `Result` instance by using the `MapToResult` method. + +The `MapToResult` methods can accepts an error as a parameter and returns a `Result` instance with the specified error +in case the `Maybe` instance is empty. + +For example, consider the following code snippet: + +```csharp +var result = Maybe + .From(someFactoryMethod()) + .MapToResult(new NotFoundError("Value not found")) + .Bind(ValidateValue) + .Bind(UpdateValue); -The `ToResult` method accepts an error as a parameter and returns a `Result` instance with the specified error -in case the `Maybe` instance is empty. \ No newline at end of file +``` \ No newline at end of file