Socket
Book a DemoInstallSign in
Socket

PG.FunctionalExt

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

PG.FunctionalExt

This package contains implementations of the Option monad and the Result.

nugetNuGet
Version
0.2.2
Version published
Maintainers
1
Created
Source

FunctionalExt

Functional programming types Result and Option

Option Type

The Option type represents a value that may or may not exist. It is useful for modeling optional values without resorting to null references. The Option type has two possible states:

  • Some(value): Represents an existing value.
  • None: Represents the absence of a value.

Example Usage

Option<int> maybeNumber = Some(42);
Option<int> noNumber = None<int>();

maybeNumber.Match(
    some: value => Console.WriteLine($"Value: {value}"),
    none: () => Console.WriteLine("No value")
);

Result Type

The Result type represents the outcome of an operation that can either succeed or fail. It is useful for error handling without using exceptions. The Result type has two possible states:

  • Success(value): Represents a successful result with a value.
  • Fail(error): Represents a failure with an error.

Example Usage

Result<int, GenericError> divide(int numerator, int denominator)
{
    if (denominator == 0)
        return Fail<int, GenericError>(new GenericError("Division by zero"));
    return Success<int, GenericError>(numerator / denominator);
}

var result = divide(10, 2);
result.Match(
    success: value => Console.WriteLine($"Result: {value}"),
    error: err => Console.WriteLine($"Error: {err}")
);

Installation

To use this library, add it to your project via NuGet:

dotnet add package FunctionalExt

License

This project is licensed under the MIT License. See the LICENSE file for details.

Keywords

Option

FAQs

Package last updated on 20 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts