The Nullable
extensions turns the Nullable<T>
type from .NET into a monad. This means you can use them in LINQ expressions, just like
the other monadic types in this library. There are natural transformation functions to help convert from a nullable into other types, i.e.
int? x = ...
Option<int> mx = x.ToOption();
Contents
- Prelude
- toOption <T> (T? self)
- match <T, R> (T? self, Func<T, R> Some, Func<R> None)
- matchAsync <T, R> (T? self, Func<T, Task<R>> Some, Func<R> None)
- matchAsync <T, R> (T? self, Func<T, Task<R>> Some, Func<Task<R>> None)
- match <T> (T? self, Action<T> Some, Action None)
- ifSome <T> (T? self, Action<T> someHandler)
- ifSome <T> (T? self, Func<T, Unit> someHandler)
- ifNone <T> (T? self, Func<T> None)
- ifNone <T> (T? self, T noneValue)
- toEither <L, T> (T? self, L defaultLeftValue)
- toEither <L, T> (T? self, Func<L> Left)
- append <T> (T? lhs, T? rhs)
- plus <NUM, T> (T? lhs, T? rhs)
- subtract <NUM, T> (T? lhs, T? rhs)
- product <NUM, T> (T? lhs, T? rhs)
- divide <NUM, T> (T? lhs, T? rhs)
- somes <T> (IEnumerable<T?> self)
- iter <T> (T? self, Action<T> action)
- count <T> (T? self)
- forall <T> (T? self, Func<T, bool> pred)
- forall <T> (T? self, Func<T, bool> Some, Func<bool> None)
- exists <T> (T? self, Func<T, bool> pred)
- exists <T> (T? self, Func<T, bool> Some, Func<bool> None)
- map <T, R> (T? self, Func<T, R> mapper)
- map <T, R> (T? self, Func<T, R> Some, Func<R> None)
- filter <T> (T? self, Func<T, bool> pred)
- filter <T> (T? self, Func<T, bool> Some, Func<bool> None)
- bind <T, R> (T? self, Func<T, R?> binder)
- bind <T, R> (T? self, Func<T, R?> Some, Func<R?> None)
- sum (int? self)
Methods
method Option<T> toOption <T> (T? self) Source #
Convert NullableT to OptionT
Parameters
type | T | |
param | self | Value to convert |
returns | OptionT with Some or None, depending on HasValue |
method R match <T, R> (T? self, Func<T, R> Some, Func<R> None) Source #
Match the two states of the Nullable and return a non-null R.
Parameters
type | R | Return type |
param | Some | Some handler |
param | None | None handler |
returns | A non-null R |
method Task<R> matchAsync <T, R> (T? self, Func<T, Task<R>> Some, Func<R> None) Source #
Match the two states of the Nullable and return a promise for an R.
Parameters
type | R | Return type |
param | Some | Some handler |
param | None | None handler |
returns | A promise to return an R |
method Task<R> matchAsync <T, R> (T? self, Func<T, Task<R>> Some, Func<Task<R>> None) Source #
Match the two states of the Nullable and return a promise for an R.
Parameters
type | R | Return type |
param | Some | Some handler |
param | None | None handler |
returns | A promise to return an R |
method Unit match <T> (T? self, Action<T> Some, Action None) Source #
Match the two states of the Nullable T
Parameters
param | Some | Some match |
param | None | None match |
method Unit ifSome <T> (T? self, Action<T> someHandler) Source #
Invokes the someHandler if Nullable is in the Some state, otherwise nothing happens.
method Unit ifSome <T> (T? self, Func<T, Unit> someHandler) Source #
Invokes the someHandler if Nullable is in the Some state, otherwise nothing happens.
method T? append <T> (T? lhs, T? rhs) Source #
Append the Some(x) of one option to the Some(y) of another. For numeric values the behaviour is to sum the Somes (lhs + rhs) For string values the behaviour is to concatenate the strings For Lst/Stck/Que values the behaviour is to concatenate the lists For Map or Set values the behaviour is to merge the sets Otherwise if the T type derives from IAppendable then the behaviour is to call lhs.Append(rhs);
Parameters
param | lhs | Left-hand side of the operation |
param | rhs | Right-hand side of the operation |
returns | lhs + rhs |
method T? plus <NUM, T> (T? lhs, T? rhs) Source #
Sum the Some(x) of one nullable from the Some(y) of another. For numeric values the behaviour is to find the subtract between the Somes (lhs - rhs) For Lst values the behaviour is to remove items in the rhs from the lhs For Map or Set values the behaviour is to remove items in the rhs from the lhs Otherwise if the T type derives from ISubtractable then the behaviour is to call lhs.Plus(rhs);
Parameters
param | lhs | Left-hand side of the operation |
param | rhs | Right-hand side of the operation |
returns | lhs - rhs |
method T? subtract <NUM, T> (T? lhs, T? rhs) Source #
Subtract the Some(x) of one nullable from the Some(y) of another. For numeric values the behaviour is to find the subtract between the Somes (lhs - rhs) For Lst values the behaviour is to remove items in the rhs from the lhs For Map or Set values the behaviour is to remove items in the rhs from the lhs Otherwise if the T type derives from ISubtractable then the behaviour is to call lhs.Subtract(rhs);
Parameters
param | lhs | Left-hand side of the operation |
param | rhs | Right-hand side of the operation |
returns | lhs - rhs |
method T? product <NUM, T> (T? lhs, T? rhs) Source #
Find the product of the Somes. For numeric values the behaviour is to multiply the Somes (lhs * rhs) For Lst values the behaviour is to multiply all combinations of values in both lists to produce a new list Otherwise if the T type derives from IMultiplicable then the behaviour is to call lhs.Product(rhs);
Parameters
param | lhs | Left-hand side of the operation |
param | rhs | Right-hand side of the operation |
returns | lhs * rhs |
method T? divide <NUM, T> (T? lhs, T? rhs) Source #
Divide the Somes. For numeric values the behaviour is to divide the Somes (lhs / rhs) For Lst values the behaviour is to divide all combinations of values in both lists to produce a new list Otherwise if the T type derives from IDivisible then the behaviour is to call lhs.Divide(rhs);
Parameters
param | lhs | Left-hand side of the operation |
param | rhs | Right-hand side of the operation |
returns | lhs / rhs |
method IEnumerable<T> somes <T> (IEnumerable<T?> self) Source #
Extracts from a list of 'Option' all the 'Some' elements. All the 'Some' elements are extracted in order.
method Unit iter <T> (T? self, Action<T> action) Source #
Iterate Nullable. Imagine the item has zero or one items depending on whether it's in a None state or not.
Parameters
param | action | Action to invoke with the value if not in None state |
method int count <T> (T? self) Source #
Returns 1 if there is a value, 0 otherwise
Parameters
returns | 1 if there is a value, 0 otherwise |
method bool forall <T> (T? self, Func<T, bool> pred) Source #
ForAll Nullable. Imagine the item has zero or one items depending on whether it's in a None state or not. This function runs a predicate against the value if it exists, returns true if it doesn't (because the predicate holds 'for all' items).
Parameters
param | pred | Predicate |
method bool forall <T> (T? self, Func<T, bool> Some, Func<bool> None) Source #
ForAll Nullable. Imagine the item has zero or one items depending on whether it's in a None state or not. This function runs a predicate against the value if it exists, returns true if it doesn't (because the predicate holds 'for all' items).
Parameters
param | Some | Some predicate |
param | None | None predicate |
method bool exists <T> (T? self, Func<T, bool> pred) Source #
Exists Nullable. Imagine the item has zero or one items depending on whether it's in a None state or not. This function runs a predicate against the value if it exists, returns false if it doesn't.
Parameters
param | pred | Predicate |
method bool exists <T> (T? self, Func<T, bool> Some, Func<bool> None) Source #
Exists Nullable. Imagine the item has zero or one items depending on whether it's in a None state or not. This function runs a predicate against the value if it exists, returns false if it doesn't.
Parameters
param | Some | Some predicate |
param | None | None predicate |
method R? map <T, R> (T? self, Func<T, R> Some, Func<R> None) Source #