OptionType implementation in C#
Could be downloaded from NuGet:
Install-Package OptionType
- via Option static method:
var result = Option<string>.Some("on nie wiedzial");
var none = Option<string>.None;
- via
Some
extension method:
var anotherResult = "on nie wiedzial".Some();
- via
Some
extension method with predicate:
var anotherResult = "on nie wiedzial".Some(x => !string.IsNullOrWhitespace(x));
- via
None
extension method with predicate:
var anotherResult = "on nie wiedzial".None(x => !string.IsNullOrWhitespace(x));
- via implicit cast:
Option<string> anotherAnotherResult = "on nie wiedzial";
- via
IsSome
andIsNone
properties on aOptionType
object.
OptionType.Validation package provides a simple Rule class to defines Rules which should apply to some objects and as a result returns OptionType.
Could be downloaded from NuGet:
Install-Package OptionType.Validation
example usage looks like this:
var rules = new[]
{
new Rule(() => "name".StartsWith("n"), "name"),
new Rule(() => "dd".StartsWith("e"), "dd"),
new Rule(() => "hh".StartsWith("a"), "hh"),
new Rule(() => "hehe".StartsWith("h"), "hehe"),
};
var result = rules.Apply();