LanguageExt.Core

LanguageExt.Core Monads Alternative Value Monads Nullable

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

class Prelude Source #

Methods

method Option<T> toOption <T> (T? self) Source #

where T : struct

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 #

where T : struct

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 #

where T : struct

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 #

where T : struct

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 #

where T : struct

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 #

where T : struct

Invokes the someHandler if Nullable is in the Some state, otherwise nothing happens.

method Unit ifSome <T> (T? self, Func<T, Unit> someHandler) Source #

where T : struct

Invokes the someHandler if Nullable is in the Some state, otherwise nothing happens.

method T ifNone <T> (T? self, Func<T> None) Source #

where T : struct

method T ifNone <T> (T? self, T noneValue) Source #

where T : struct

method Either<L, T> toEither <L, T> (T? self, L defaultLeftValue) Source #

where T : struct

method Either<L, T> toEither <L, T> (T? self, Func<L> Left) Source #

where T : struct

method T? append <T> (T? lhs, T? rhs) Source #

where T : struct, Semigroup<T>

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 #

where T : struct
where NUM : Arithmetic<T>

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 #

where T : struct
where NUM : Arithmetic<T>

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 #

where T : struct
where NUM : Arithmetic<T>

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 #

where T : struct
where NUM : Num<T>

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 #

where T : struct

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 #

where T : struct

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 #

where T : struct

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 #

where T : struct

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 #

where T : struct

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 #

where T : struct

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 #

where T : struct

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> mapper) Source #

where T : struct
where R : struct

method R? map <T, R> (T? self, Func<T, R> Some, Func<R> None) Source #

where T : struct
where R : struct

method T? filter <T> (T? self, Func<T, bool> pred) Source #

where T : struct

method T? filter <T> (T? self, Func<T, bool> Some, Func<bool> None) Source #

where T : struct

method R? bind <T, R> (T? self, Func<T, R?> binder) Source #

where T : struct
where R : struct

method R? bind <T, R> (T? self, Func<T, R?> Some, Func<R?> None) Source #

where T : struct
where R : struct

method int sum (int? self) Source #