OptionReturnValues_balfourcraig NuGet Package

Provides types for returning values without nulls.
Provides three classes of the interface IOption<T>:
* Some<T> is a class for holding a valid value.

It holds one readonly value which is set in the constructor. This is to immutable.
* None<T> is a readonly struct for holding nothing. This is replacing null.
* Err<T> class holds a readonly exception (set in constructor) as ex which can be used for returning errors without throwing them until you need.

IOption<T> provides one public method: bool HasValue(out T value) which can be used to check if the returned type is a Some<T>, and if it is, to get the value in the out parameter. Use this with care, as if it returns false, value will be default, which is often null.

Best to define the out parameter inline to prevent using it wrongly. eg:
if(option.HasValue(out string answer)){
//do stuff with answer here}.




Got any OptionReturnValues_balfourcraig Question?





Info

Version: 1.0.4
Author(s): balfourcraig
Last Update: Tuesday, August 28, 2018
.NET Fiddle: Create the first Fiddle
NuGet Url: https://www.nuget.org/packages/OptionReturnValues_balfourcraig


Install
Install-Package OptionReturnValues_balfourcraig
dotnet add package OptionReturnValues_balfourcraig
paket add OptionReturnValues_balfourcraig
OptionReturnValues_balfourcraig Download (Unzip the "nupkg" after downloading)





STATS

must-have-score

avg-downloads-per-day

1

days-since-last-release

2040