Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mnie/optiontype
Implementation of Option in C#.
https://github.com/mnie/optiontype
Last synced: 2 days ago
JSON representation
Implementation of Option in C#.
- Host: GitHub
- URL: https://github.com/mnie/optiontype
- Owner: MNie
- License: mit
- Created: 2018-08-16T19:38:45.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-03T05:41:45.000Z (over 4 years ago)
- Last Synced: 2024-10-06T22:19:08.012Z (about 1 month ago)
- Language: C#
- Size: 17.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OptionType & OptionType.Validation
* NuGet Status
| | OptionType | OptionType.Validation |
|---|---|---|
| nuget | [![NuGet](https://buildstats.info/nuget/OptionType?includePreReleases=true)](https://www.nuget.org/packages/OptionType) | [![NuGet](https://buildstats.info/nuget/OptionType.Validation?includePreReleases=true)](https://www.nuget.org/packages/OptionType.Validation) |* Build Status
[![Build Status](https://travis-ci.org/MNie/OptionType.svg?branch=master)](https://travis-ci.org/MNie/OptionType)# OptionType
OptionType implementation in C#Could be downloaded from NuGet:
```Install-Package OptionType```# usage
- via Option static method:
```csharp
var result = Option.Some("on nie wiedzial");var none = Option.None;
```- via `Some` extension method:
```csharp
var anotherResult = "on nie wiedzial".Some();
```- via `Some` extension method with predicate:
```csharp
var anotherResult = "on nie wiedzial".Some(x => !string.IsNullOrWhitespace(x));
```- via `None` extension method with predicate:
```csharp
var anotherResult = "on nie wiedzial".None(x => !string.IsNullOrWhitespace(x));
```- via implicit cast:
```csharp
Option anotherAnotherResult = "on nie wiedzial";
```# How to check what `option` contains?
- via `IsSome` and `IsNone` properties on a `OptionType` object.
# OptionType.Validation
[OptionType.Validation](https://www.nuget.org/packages/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:
```csharp
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();
```