ResultSharp.Core 1.3.0

dotnet add package ResultSharp.Core --version 1.3.0
                    
NuGet\Install-Package ResultSharp.Core -Version 1.3.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ResultSharp.Core" Version="1.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ResultSharp.Core" Version="1.3.0" />
                    
Directory.Packages.props
<PackageReference Include="ResultSharp.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ResultSharp.Core --version 1.3.0
                    
#r "nuget: ResultSharp.Core, 1.3.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ResultSharp.Core@1.3.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ResultSharp.Core&version=1.3.0
                    
Install as a Cake Addin
#tool nuget:?package=ResultSharp.Core&version=1.3.0
                    
Install as a Cake Tool

ResultSharp

ResultSharp is a Rust-like error and null handling package for C#. It provides Option and Result types to handle optional values and error handling in a more expressive and safer way.

Features

  • Option<T> type for handling optional values.
  • Result<T> type for handling operations that can succeed or fail.
  • Extension methods for mapping and transforming Option and Result types.
  • Asynchronous support for mapping Option and Result types.

Installation

To install ResultSharp, add the following package reference to your project file:

<PackageReference Include="ResultSharp" Version="1.2.0" />

Alternatively, you can install it via the .NET CLI:

dotnet add package ResultSharp --version 1.3.0

Usage

Here is a simple example of how to use ResultSharp:

using ResultSharp;

public class Example
{
  public static void Main()
  {
     var result = Result.Ok("Success");
     var message = result switch
     {
         Ok<string> ok => $"Operation succeeded with value: {ok.Value}",
         Err<string> err => $"Operation failed with error: {err.Exception.Message}",
         _ => "Unknown result",
     };
  }
}

Mapping and Transforming

You can use the Map and MapAsync methods to transform Option and Result types.

Synchronous Mapping
using ResultSharp;

public class Example
{
  public static void Main()
  {
    var option = Option.Some(5);
    var mappedOption = option.Map(x => x * 2);
    Console.WriteLine(mappedOption); // Output: Some(10)

    var result = Result.Ok(5);
    var mappedResult = result.Map(x => x * 2);
    Console.WriteLine(mappedResult); // Output: Ok(10)
  }
}
Asynchronous Mapping
using ResultSharp;
using System.Threading.Tasks;

public class Example
{
  public static async Task Main()
  {
    var optionTask = Task.FromResult(Option.Some(5));
    var mappedOption = await optionTask.MapAsync(async x => await Task.FromResult(x * 2));
    Console.WriteLine(mappedOption); // Output: Some(10)

    var resultTask = Task.FromResult(Result.Ok(5));
    var mappedResult = await resultTask.MapAsync(async x => await Task.FromResult(x * 2));
    Console.WriteLine(mappedResult); // Output: Ok(10)
  }
}

Contributing

We welcome contributions to ResultSharp! If you would like to contribute, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bugfix.
  3. Make your changes.
  4. Submit a pull request with a detailed description of your changes.

Please make sure to follow the coding standards and write tests for your changes.

License

ResultSharp is licensed under the MIT License. See the LICENSE file for more information.

Contact

If you have any questions or feedback, feel free to open an issue on GitHub or contact us at geffc1454@gmail.com.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.