# `Geekeey.Extensions.Result` Result is a .NET library which provides a Result type for representing the outcome of operations in C#. It offers a clean and concise way to handle success and failure scenarios, promoting better error handling and code readability. ## Features - **Success and Failure States:** Represent successful outcomes with a value (`Prelude.Success()`) or failures with an error (`Prelude.Failure()`). - **Immutability:** `Result` objects are immutable, ensuring thread safety and preventing accidental modification. - **Chaining Operations:** Methods like `Map` and `Then` allow for chaining operations on successful results, promoting a functional programming style. ## Getting Started ### Install the NuGet package: ``` dotnet add package Geekeey.Extensions.Result ``` You may need to add our NuGet Feed to your `nuget.config` this can be done by adding the following lines ```xml ``` ### Configure The package adds a global using for the functions in the `Prelude` class when the `ImplicitUsings` is enabled in the `.csproj` file. This global using is recommended but can also be removed, by removing the `Geekeey.Extensions.Result.Prelude` value from the item group ``. For more information about that see the `Project.props` file inside the project tree. ### Usage ```csharp public Result Divide(int dividend, int divisor) { if (divisor == 0) { return Prelude.Failure("Division by zero"); } return Prelude.Success(dividend / divisor); } if (result.IsSuccess) { Console.WriteLine("Result: " + result.Value); } else { Console.WriteLine("Error: " + result.Error); } ``` ```csharp _ = await Prelude.Try(() => File.ReadAllLines("i_do_not_exist.txt")) .ThenAsync(static async Task>> (list) => { using var client = new HttpClient(); Task> DoSomeThing(string line) => Prelude.TryAsync(() => client.GetAsync(line)) .Map(static async response => int.Parse(await response.Content.ReadAsStringAsync())); var results = await Task.WhenAll(list.Select(DoSomeThing).ToArray()); return results.Join(); }); ```