nunohpinheiro / toolpack-domain-utils

Useful domain components for .NET solutions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ToolPack Domain Utils

Useful opinionated domain components and/or helper functions for .NET solutions.

ToolPack.DomainUtils.Functional

Classes and interfaces to help with functional programming in C#.

Result<T>, Result, Error and Success

This is a simple implementation of the Result pattern in C#.

The package contains Result<T> and Result (i.e. Result<Success>) classes, used to represent the result of an operation that can succeed or fail:

  • In case of success, the Value property (of type T) will contain the successful output of the operation,
  • In case of failure, the Error property will contain the Error output of the operation.

The Error class represents operation errors with all their details.

Useful references:

Result extension methods

The package contains a set of extension methods to help with the handling of Result instances:

  • Execute/ExecuteAsync execute a Result function or action if the input result is successful, or return the initial Error in case of input failure;
  • Log methods log the output of the input Result instance, depending on the input result being a success or error;
  • Map/MapAsync methods apply functions of generic return type, depending on the input result being a success or error;
  • Pipe/PipeAsync methods apply a Result function to the Value of an input Result<T> instance if it is successful, or return the initial Error in case of input failure;
  • Switch/SwitchAsync methods run actions, depending on the input result being a success or error.

These methods are useful to chain operations and handle the output of each operation in a functional way.

They intend to help with the implementation of the Railway Oriented Programming (ROP) pattern.

Useful references:

About

Useful domain components for .NET solutions

License:MIT License


Languages

Language:C# 100.0%