Skip to content

DropBear Codex is a .NET library that enhances operation result management and data integrity with `Result`, `Result<T>`, and `ResultWithPayload<T>` types, complete with checksum verification. Featuring custom MessagePack serialization for complex types, it ensures efficient, secure data handling.

Notifications You must be signed in to change notification settings

tkuchel/DropBear.Codex.Core

Repository files navigation

Result Class Library

This library provides a set of tools for managing operation results in a robust and railway-oriented programming fashion. It offers various result types to encapsulate the outcomes of operations, handling both successes and failures gracefully without throwing exceptions. This approach enhances error handling, makes your codebase cleaner, and improves the maintainability of your applications.

Features

  • Generic Result Types: Handle different data types and operations flexibly.
  • Railway-Oriented Programming: Built-in methods for chaining operations based on success or failure outcomes.
  • Error Handling: Advanced error handling capabilities without relying on exceptions.
  • Asynchronous Support: Asynchronous methods to handle I/O-bound and CPU-intensive operations efficiently.

Installation

To install the Result Class Library, use the following NuGet command:

dotnet add package DropBear.Codex.Core

Usage Examples

Below are some examples of how to use the various result types provided by the library:

Using Result

var result = Result.Success();
if (result.IsSuccess)
{
    Console.WriteLine("Operation succeeded.");
}

var failureResult = Result.Failure("Error occurred.");
failureResult.OnFailure(error => Console.WriteLine(error));

Using Result<T>

var result = Result.Success(123);
var nextResult = result.Bind(value => Result.Success(value.ToString()));
nextResult.OnSuccess(value => Console.WriteLine($"Processed value: {value}"));

Using Result<TSuccess, TFailure>

var result = Result.Success<int, string>(42);
result.Match(
    success => Console.WriteLine($"Success with value: {success}"),
    failure => Console.WriteLine($"Failed with error: {failure}")
);

Using Result<TSuccess, TFailure> with Additional Handlers

var result = Result.Success<int, string>(42);
result.Match(
    success => Console.WriteLine($"Success with value: {success}"),
    failure => Console.WriteLine($"Failed with error: {failure}"),
    onPending: () => Console.WriteLine("Operation is pending."),
    onCancelled: () => Console.WriteLine("Operation was cancelled."),
    onWarning: () => Console.WriteLine("Operation completed with warnings."),
    onPartialSuccess: () => Console.WriteLine("Operation partially succeeded."),
    onNoOp: () => Console.WriteLine("No operation was performed.")
);

Using ResultWithPayload<T>

var data = new { Name = "Example", Value = 42 };
var result = Result.SuccessWithPayload(data);
var deserialized = result.DecompressAndDeserialize();
if (deserialized.IsSuccess)
{
    Console.WriteLine($"Data: {deserialized.Value.Name}");
}

Contributing

Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the GNU LGPL v3. See LICENSE for more information.

Contact

Terrence Kuchel (DropBear) - Contact me via GitHub. Project Link: GitHub

Acknowledgements

  • Thanks to all contributors who participate in this project.
  • Special thanks to those who contribute to railway-oriented programming ideas and patterns.

Development Status

Note: This library is relatively new and under active development. While it is being developed with robustness and best practices in mind, it may still be evolving.

We encourage you to test thoroughly and contribute if possible before using this library in a production environment. The API and features may change as feedback is received and improvements are made. We appreciate your understanding and contributions to making this library better!

Please use the following link to report any issues or to contribute: GitHub Issues.

About

DropBear Codex is a .NET library that enhances operation result management and data integrity with `Result`, `Result<T>`, and `ResultWithPayload<T>` types, complete with checksum verification. Featuring custom MessagePack serialization for complex types, it ensures efficient, secure data handling.

Resources

Stars

Watchers

Forks

Packages

No packages published