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();
- NullableExtensions
- ToOption <T> (this T? self)
- ToSeq <A> (this A? self)
- AsEnumerable <T> (this T? self)
- Match <T, R> (this T? self, Func<T, R> Some, Func<R> None)
- MatchAsync <T, R> (this T? self, Func<T, Task<R>> Some, Func<R> None)
- MatchAsync <T, R> (this T? self, Func<T, Task<R>> Some, Func<Task<R>> None)
- Match <T> (this T? self, Action<T> Some, Action None)
- IfSome <T> (this T? self, Action<T> someHandler)
- IfSome <T> (this T? self, Func<T, Unit> someHandler)
- IfNone <T> (this T? self, Func<T> None)
- IfNone <T> (this T? self, T noneValue)
- ToList <T> (this T? self)
- ToArray <T> (this T? self)
- ToEither <L, T> (this T? self, L defaultLeftValue)
- ToEither <L, T> (this T? self, Func<L> Left)
- ToEitherUnsafe <L, T> (this T? self, L defaultLeftValue)
- ToEitherUnsafe <L, T> (this T? self, Func<L> Left)
- ToTryOption <L, T> (this T? self, L defaultLeftValue)
- Append <SEMI, T> (this T? lhs, T? rhs)
- Plus <NUM, T> (this T? lhs, T? rhs)
- Subtract <NUM, T> (this T? lhs, T? rhs)
- Product <NUM, T> (this T? lhs, T? rhs)
- Divide <NUM, T> (this T? lhs, T? rhs)
- Somes <T> (this IEnumerable<T?> self)
- Iter <T> (this T? self, Action<T> action)
- Count <T> (this T? self)
- ForAll <T> (this T? self, Func<T, bool> pred)
- ForAll <T> (this T? self, Func<T, bool> Some, Func<bool> None)
- Exists <T> (this T? self, Func<T, bool> pred)
- Exists <T> (this T? self, Func<T, bool> Some, Func<bool> None)
- Fold <S, T> (this T? self, S state, Func<S, T, S> folder)
- Fold <S, T> (this T? self, S state, Func<S, T, S> Some, Func<S, S> None)
- Map <T, R> (this T? self, Func<T, R> mapper)
- Map <T, R> (this T? self, Func<T, R> Some, Func<R> None)
- Filter <T> (this T? self, Func<T, bool> pred)
- Filter <T> (this T? self, Func<T, bool> Some, Func<bool> None)
- Bind <T, R> (this T? self, Func<T, R?> binder)
- Bind <T, R> (this T? self, Func<T, R?> Some, Func<R?> None)
- Select <T, U> (this T? self, Func<T, U> map)
- Where <T> (this T? self, Func<T, bool> pred)
- Sum (this int? self)
- SelectMany <T, U, V> (this T? self, Func<T, U?> bind, Func<T, U, V> project )
- 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)
- toEitherUnsafe <L, T> (T? self, L defaultLeftValue)
- toEitherUnsafe <L, T> (T? self, Func<L> Left)
- toTryOption <L, T> (T? self, L defaultLeftValue)
- append <SEMI, 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)
- fold <S, T> (T? self, S state, Func<S, T, S> folder)
- fold <S, T> (T? self, S state, Func<S, T, S> Some, Func<S, S> 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)
class NullableExtensions Source #
method Option<T> ToOption <T> (this T? self) Source #
Convert NullableT to OptionT
type | T | |
param | self | Value to convert |
returns | OptionT with Some or None, depending on HasValue |
method Seq<A> ToSeq <A> (this A? self) Source #
Convert Nullable to Seq (0..1 entries)
type | T | |
param | self | Value to convert |
returns | Zero or One values, depending on HasValue |
method Seq<T> AsEnumerable <T> (this T? self) Source #
Convert NullableT to IEnumerableT (0..1 entries)
type | T | |
param | self | Value to convert |
returns | Zero or One enumerable values, depending on HasValue |
method R Match <T, R> (this T? self, Func<T, R> Some, Func<R> None) Source #
Match the two states of the Nullable and return a non-null R.
type | R | Return type |
param | Some | Some handler |
param | None | None handler |
returns | A non-null R |
method Task<R> MatchAsync <T, R> (this 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.
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> (this 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.
type | R | Return type |
param | Some | Some handler |
param | None | None handler |
returns | A promise to return an R |
method Unit Match <T> (this T? self, Action<T> Some, Action None) Source #
Match the two states of the Nullable T
param | Some | Some match |
param | None | None match |
method Unit IfSome <T> (this T? self, Action<T> someHandler) Source #
Invokes the someHandler if Nullable is in the Some state, otherwise nothing happens.
method Unit IfSome <T> (this T? self, Func<T, Unit> someHandler) Source #
Invokes the someHandler if Option is in the Some state, otherwise nothing happens.
method EitherUnsafe<L, T> ToEitherUnsafe <L, T> (this T? self, L defaultLeftValue) Source #
method EitherUnsafe<L, T> ToEitherUnsafe <L, T> (this T? self, Func<L> Left) Source #
method T? Append <SEMI, T> (this 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);
param | lhs | Left-hand side of the operation |
param | rhs | Right-hand side of the operation |
returns | lhs + rhs |
method T? Plus <NUM, T> (this 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);
param | lhs | Left-hand side of the operation |
param | rhs | Right-hand side of the operation |
returns | lhs - rhs |
method T? Subtract <NUM, T> (this 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);
param | lhs | Left-hand side of the operation |
param | rhs | Right-hand side of the operation |
returns | lhs - rhs |
method T? Product <NUM, T> (this 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);
param | lhs | Left-hand side of the operation |
param | rhs | Right-hand side of the operation |
returns | lhs * rhs |
method T? Divide <NUM, T> (this 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);
param | lhs | Left-hand side of the operation |
param | rhs | Right-hand side of the operation |
returns | lhs / rhs |
method IEnumerable<T> Somes <T> (this IEnumerable<T?> self) Source #
Extracts from a list of nullables all the HasValue elements. All the 'Some' elements are extracted in order.
method Unit Iter <T> (this 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.
param | action | Action to invoke with the value if not in None state |
method int Count <T> (this T? self) Source #
Returns 1 if there is a value, 0 otherwise
returns | 1 if there is a value, 0 otherwise |
method bool ForAll <T> (this 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).
param | pred | Predicate |
method bool ForAll <T> (this 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).
param | Some | Some predicate |
param | None | None predicate |
method bool Exists <T> (this 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.
param | pred | Predicate |
method bool Exists <T> (this 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.
param | Some | Some predicate |
param | None | None predicate |
method S Fold <S, T> (this T? self, S state, Func<S, T, S> folder) Source #
Folds Nullable into an S. wikipedia.org/wiki/Fold_(higher-order_function)
param | tryDel | Try to fold |
param | state | Initial state |
param | folder | Fold function |
returns | Folded state |
method S Fold <S, T> (this T? self, S state, Func<S, T, S> Some, Func<S, S> None) Source #
Folds Nullable into an S. wikipedia.org/wiki/Fold_(higher-order_function)
param | tryDel | Try to fold |
param | state | Initial state |
param | Some | Fold function for Some |
param | None | Fold function for None |
returns | Folded state |
method R? Map <T, R> (this T? self, Func<T, R> Some, Func<R> None) Source #
method R? Bind <T, R> (this T? self, Func<T, R?> Some, Func<R?> None) Source #
method V? SelectMany <T, U, V> (this T? self, Func<T, U?> bind, Func<T, U, V> project ) Source #
method Option<T> toOption <T> (T? self) Source #
Convert NullableT to OptionT
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.
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.
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.
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
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 EitherUnsafe<L, T> toEitherUnsafe <L, T> (T? self, L defaultLeftValue) Source #
method T? append <SEMI, 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);
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);
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);
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);
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);
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.
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
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).
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).
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.
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.
param | Some | Some predicate |
param | None | None predicate |
method S fold <S, T> (T? self, S state, Func<S, T, S> folder) Source #
Folds Nullable into an S. https://en.wikipedia.org/wiki/Fold_(higher-order_function)
param | tryDel | Try to fold |
param | state | Initial state |
param | folder | Fold function |
returns | Folded state |
method S fold <S, T> (T? self, S state, Func<S, T, S> Some, Func<S, S> None) Source #
Folds Nullable into an S. https://en.wikipedia.org/wiki/Fold_(higher-order_function)
param | tryDel | Try to fold |
param | state | Initial state |
param | Some | Fold function for Some |
param | None | Fold function for None |
returns | Folded state |
method R? map <T, R> (T? self, Func<T, R> Some, Func<R> None) Source #