An open API service indexing awesome lists of open source software.

https://github.com/yortw/maybe.sharp

A generic 'option' type for .Net, explicitly representing a value that is either 'something' or 'nothing'.
https://github.com/yortw/maybe.sharp

dotnet maybe net40 netstandard option

Last synced: 29 days ago
JSON representation

A generic 'option' type for .Net, explicitly representing a value that is either 'something' or 'nothing'.

Awesome Lists containing this project

README

          

# Maybe.Sharp
A generic 'option' type for .Net, explicitly representing a value that is either 'something' or 'nothing'.

[![GitHub license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/Yortw/Maybe.Sharp/blob/master/LICENSE) [![Coverage Status](https://coveralls.io/repos/github/Yortw/Maybe.Sharp/badge.svg?branch=master)](https://coveralls.io/github/Yortw/Maybe.Sharp?branch=master) [![Build status](https://ci.appveyor.com/api/projects/status/yxjln5gns7qcbt9v?svg=true)](https://ci.appveyor.com/project/Yortw/maybe-sharp) [![NuGet Badge](https://buildstats.info/nuget/Maybe.Sharp)](https://www.nuget.org/packages/Maybe.Sharp/)

```powershell
PM> Install-Package Maybe.Sharp
```

# Why ?
Yes there are plenty of maybe/option types for .Net, but I couldn't find one that met all my requirements, hence Maybe.Sharp exists.

# Features
See the [API Documentation](api/MaybeSharp.Maybe-1.html) for contents/help.

* Struct/Value type
* Instances of Maybe cannot be null

* (In)Equality & GetHashCode overrides/implementation
* \> \< >= <= operators for Maybe and T values.
* Implements IComparable, IComparable>, IComparable, IEquatable>, IEquatable, IFormattable
* Implict cast from T to Maybe
* Explicit cast from Maybe to T (exception when 'nothing')
* Bind method for piping Maybe through functions
* Chainable WhenSomething/WhenNothing for control flow
* Static Nothing value for each Maybe type.
* Maybe of other value types (not just reference types), i.e Maybe of System.Guid is 'empty'/'nothing when the inner value is System.Guid.Empty. Same for DateTime when the value is DateTime.MinValue etc.
* Cast/As methods for converting Maybe to Maybe
* ToString override
* TryGetValue extension for IDictionary
* Or method to Coalesce Maybe
* ValueOr method for retrieving wrapped value or default value when empty
* ToNullable to convert Maybe to a Nullable equivalent
* ToMaybe extension for Nullable values.
* LINQ support via where and select extensions
* TryParse extensions for System.String