Maybe.Sharp
A generic 'option' type for .Net, explicitly representing a value that is either 'something' or 'nothing'.
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 for contents/help.
Struct/Value type
- Instances of Maybe
cannot be null
- Instances of Maybe
(In)Equality & GetHashCode overrides/implementation
- > < >= <= operators for Maybe
and T values. - Implements IComparable
, IComparable<Maybe >, IComparable, IEquatable<Maybe >, 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<K, V>
- 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