Orx.Fun.Option 1.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Orx.Fun.Option --version 1.2.0                
NuGet\Install-Package Orx.Fun.Option -Version 1.2.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="Orx.Fun.Option" Version="1.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Orx.Fun.Option --version 1.2.0                
#r "nuget: Orx.Fun.Option, 1.2.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.
// Install Orx.Fun.Option as a Cake Addin
#addin nuget:?package=Orx.Fun.Option&version=1.2.0

// Install Orx.Fun.Option as a Cake Tool
#tool nuget:?package=Orx.Fun.Option&version=1.2.0                

Orx.Fun.Option

An option type for C# aiming to be explicit while concise.

Complete auto-generated documentation can be found here: sandcastle-documentation.

Why?

  1. Optional (maybe) values are necessary.
    • Explicit optional arguments
    • Explicit optional returns
    • Continuations without overwhelming null/none checks
    • ...
  2. Built-in nullables do not seem to satisfy the requirements.

Explicit Optional Arguments

static void Solve(Instance instance, Opt<SolverParameters> parameters = default)
{
	// solve with the parameters if provided;
	// with default parameters otherwise.
}

// caller knows that it is okay not to provide parameters
Solve(instance);
Solve(instance, None<SolverParameters>());

// or solve with parameters
SolverParameters pars = new()
{
	TimeLimit = 60,
};
Solve(instance, Some(pars));

Explicit Optional Returns

An easy example to demonstrate this is the linq method First:

var numbers = new int[] { 1, 3, 5, 7 };
int firstEven = numbers.First(x => x % 2 == 0); // throws!!!

First method actually does not (cannot always) return an int. FirstOrDefault certainly does not fix the issue. On the other hand, solution is easy with optionals:

var numbers = new int[] { 1, 3, 5, 7 };
Opt<int> firstEven = numbers.FirstOrNone(x => x % 2 == 0);

Continuations

The following dummy example illustrates the use of Map and FlatMap to enable continuations.

/// Returns Some of the user if there exists one with the given id; None otherwise
static Opt<User> GetUserById(int id)
{
	// ...
}

// task to achieve:
// 1. get the first even number
// 2. halve it
// 3. get the user with the number as id, if exists
// 4. return the users's name

var numbers = new int[] { 1, 3, 5, 7 };
Opt<string> name = numbers.FirstOrNone(x => x % 2 == 0)
    .Map(x => x / 2)
    .FlatMap(GetUserById)
    .Map(user => user.Name);


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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Orx.Fun.Option:

Package Downloads
Orx.Fun.Result

A simple result type for C#, not minding the error type, instead aiming to be explicit, concise and fluent.

Orx.MathProg

A mathematical modeling library that enables building, documenting and solving concise, simple and reusable models.

Orx.Fun.Compose

A function composition library for C#, heavily experimental right now, would be more practical if C# gets generic operator overloading.

Orx.Fun.FunVec

Unified functional collections for C# allowing access by index.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.0 274 12/19/2023
1.2.1 336 7/27/2023
1.2.0 196 7/27/2023
1.1.0 210 7/26/2023
1.0.0 368 5/5/2023