libanvl.opt
2.1.9-rc
This is a prerelease version of libanvl.opt.
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package libanvl.opt --version 2.1.9-rc
NuGet\Install-Package libanvl.opt -Version 2.1.9-rc
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="libanvl.opt" Version="2.1.9-rc" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add libanvl.opt --version 2.1.9-rc
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: libanvl.opt, 2.1.9-rc"
#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 libanvl.opt as a Cake Addin #addin nuget:?package=libanvl.opt&version=2.1.9-rc&prerelease // Install libanvl.opt as a Cake Tool #tool nuget:?package=libanvl.opt&version=2.1.9-rc&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
libanvl.Opt
A null-free optional value library for .NET.
- An optional value is represented as the base type Opt<T>
- Present values are represented as the derived type Opt<T>.Some
- Missing values are represented as the static property Opt<T>.None
See the Examples Tests for more on how to use Opt.
Requirements
Releases
- NuGet packages are available on NuGet.org
- Embedded debug symbols
- Source Link enabled
- NuGet packages from CI builds are available on the libanvl GitHub feed
Features
- Immutable
- Use Opt<T> instead of T? for optional values
- Implicit conversion from T to Opt<T>
- Opts of IEnumerable<T> are iterable
- Deep selection of properties in complex objects
- SomeOrEmpty() for string and enumerables
- SomeOrDefault() for any type
- Change to a null with SomeOrNull()
- Explicitly opt-in to exceptions with Unwrap()
- Cast inner value to compatible type with Cast()
Examples
class Car
{
public string Driver { get; set;}
}
public void AcceptOptionalValue(Opt<Car> optCar, Opt<string> optName)
{
if (optCar is Opt<Car>.Some someCar)
{
someCar.Value.Driver = optName.SomeOrDefault("Default Driver");
}
if (optCar.IsNone)
{
throw new Exception();
}
// or use Unwrap() to throw for None
Car bcar = optCar.Unwrap();
}
public void RunCarOperations()
{
var acar = new Car();
AcceptOptionalValue(acar, "Rick");
Car? nocar = null;
AcceptOptionalValue(nocar.WrapOpt(), None.String)
// use Select to project to an Opt of an inner property
Opt<string> driver = acar.Select(x => x.Driver);
}
public void OptsOfEnumerablesAreIterable<T>(Opt<List<T>> optList)
{
// if optList is None, the enumerable is empty, not null
foreach (T item in optList)
{
Console.WriteLine(item);
}
// this is equivalent
foreach (T item in optList.SomeOrEmpty())
{
Console.WriteLine(item);
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on libanvl.opt:
Package | Downloads |
---|---|
Tapanga.Plugin
Plugin API for the Tapanga terminal profile generator framework |
|
SharpSchema
Core library for the SharpSchema project. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.7.7-beta | 261 | 1/3/2025 |
2.7.6-beta | 65 | 1/3/2025 |
2.7.5-beta | 57 | 1/1/2025 |
2.6.11-beta | 42 | 12/28/2024 |
2.5.4-rc | 44 | 12/19/2024 |
2.4.4-rc | 40 | 12/19/2024 |
2.3.7-rc | 47 | 12/16/2024 |
2.2.14-rc | 50 | 12/7/2024 |
2.1.9-rc | 58 | 12/7/2024 |