https://github.com/libanvl/opt
A null-free optional value library for .NET
https://github.com/libanvl/opt
dotnet none nuget-package null-safety option optional some
Last synced: 9 months ago
JSON representation
A null-free optional value library for .NET
- Host: GitHub
- URL: https://github.com/libanvl/opt
- Owner: libanvl
- License: mit
- Created: 2021-11-13T19:29:23.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2025-03-24T20:44:56.000Z (11 months ago)
- Last Synced: 2025-05-04T01:59:04.759Z (9 months ago)
- Topics: dotnet, none, nuget-package, null-safety, option, optional, some
- Language: C#
- Homepage: https://libanvl.github.io/opt/
- Size: 144 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/libanvl/opt/actions/workflows/libanvl-dotnet-ci.yml)
[](https://github.com/libanvl/opt/actions/workflows/github-code-scanning/codeql)
[](https://www.nuget.org/packages/libanvl.opt/)
[](https://codecov.io/gh/libanvl/opt)
# libanvl.Opt
A null-free optional value library for .NET with an emphasis on minimizing additional allocations.
* An optional value is represented as the struct Opt<T>
* A possible value or error is represented as the struct Result<T, E>
* A zero to N values are represented as the struct Any<T>
See the [Examples Tests](test/libanvl.Opt.Test/Examples.cs) for more on how to use Opt.
## Requirements
[.NET 8](https://dotnet.microsoft.com/download/dotnet/8.0)
## Releases
* NuGet packages are available on [NuGet.org](https://www.nuget.org/packages/libanvl.opt)
* Embedded debug symbols
* Source Link enabled
* NuGet packages from CI builds are available on the [libanvl GitHub feed](https://github.com/libanvl/opt/packages/)
## libanvl.Opt Features
- [X] Immutable
- [X] Use Opt<T> instead of T? for optional values
- [X] Implicit conversion from T to Opt<T>
- [X] Deep selection of properties in complex objects
- [X] SomeOrDefault() for any type
- [X] Explicitly opt-in to exceptions with Unwrap()
- [X] Cast inner value to compatible type with Cast<U>()
- [ ] Opts of IEnumerable<T> are iterable
## libanvl.Result Features
- [X] Create success results with Result.Ok
- [X] Create error results with Result.Err
- [X] Unwrap values with Unwrap, throwing if the result is an error
- [X] Match on success or error with Match
- [X] Convert between Opt and Result
## libanvl.OneOrMany Features
- [X] OneOrMany<T> for a single value or a collection of values
- [X] Implicit conversions
- [X] Equality operators
## libanvl.Any Features
- [X] Any<T> for a single value or multiple values
- [X] Implicit conversions
- [X] Equality operators
- [X] Add and remove elements
- [X] Convert to array, list, or enumerable
- [X] Convert to Opt<T>
- [X] Cast elements to a compatible type
## libanvl.AnyMap Features
- [X] Dictionary-like collection that maps keys to values of type Any<V>
- [X] Implements IAnyRefMap<K, V> for reference-based operations
- [X] Get or add value by reference with GetOrAddValueRef
- [X] Get value by reference with GetValueRef
- [X] Try to get value by reference with TryGetValueRef
- [X] Perform actions on each reference with ForEachRef
- [X] Enumerate references with GetEnumerator