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'.
- Host: GitHub
- URL: https://github.com/yortw/maybe.sharp
- Owner: Yortw
- License: mit
- Created: 2017-07-16T22:59:27.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-10-12T04:10:08.000Z (over 8 years ago)
- Last Synced: 2025-01-23T05:20:11.830Z (over 1 year ago)
- Topics: dotnet, maybe, net40, netstandard, option
- Language: C#
- Homepage: https://yortw.github.io/Maybe.Sharp/
- Size: 1.35 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Maybe.Sharp
A generic 'option' type for .Net, explicitly representing a value that is either 'something' or 'nothing'.
[](https://github.com/Yortw/Maybe.Sharp/blob/master/LICENSE) [](https://coveralls.io/github/Yortw/Maybe.Sharp?branch=master) [](https://ci.appveyor.com/project/Yortw/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