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 NullableExtensions Source #

Methods

method Option<T> ToOption <T> (this 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 Seq<A> ToSeq <A> (this A? self) Source #

where A : struct

Convert Nullable to Seq (0..1 entries)

Parameters

type T
param self

Value to convert

returns

Zero or One values, depending on HasValue

method Seq<T> AsEnumerable <T> (this T? self) Source #

where T : struct

Convert NullableT to IEnumerableT (0..1 entries)

Parameters

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 #

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> (this 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> (this 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> (this 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> (this 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> (this T? self, Func<T, Unit> someHandler) Source #

where T : struct

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

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

where T : struct

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

where T : struct

method Lst<T> ToList <T> (this T? self) Source #

where T : struct

method Arr<T> ToArray <T> (this T? self) Source #

where T : struct

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

where T : struct

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

where T : struct

method EitherUnsafe<L, T> ToEitherUnsafe <L, T> (this T? self, L defaultLeftValue) Source #

where T : struct

method EitherUnsafe<L, T> ToEitherUnsafe <L, T> (this T? self, Func<L> Left) Source #

where T : struct

method TryOption<T> ToTryOption <L, T> (this T? self, L defaultLeftValue) Source #

where T : struct

method T? Append <SEMI, T> (this T? lhs, T? rhs) Source #

where SEMI : struct, Semigroup<T>
where T : struct

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> (this T? lhs, T? rhs) Source #

where T : struct
where NUM : Num<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> (this T? lhs, T? rhs) Source #

where T : struct
where NUM : Num<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> (this T? lhs, T? rhs) Source #

where T : struct
where NUM : Num<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> (this 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> (this IEnumerable<T?> self) Source #

where T : struct

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 #

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> (this 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> (this 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> (this 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> (this 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> (this 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 S Fold <S, T> (this T? self, S state, Func<S, T, S> folder) Source #

where T : struct

Parameters

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 #

where T : struct

Parameters

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

where T : struct
where R : struct

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

where T : struct
where R : struct

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

where T : struct

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

where T : struct

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

where T : struct
where R : struct

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

where T : struct
where R : struct

method U? Select <T, U> (this T? self, Func<T, U> map) Source #

where T : struct
where U : struct

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

where T : struct

method int Sum (this int? self) Source #

method V? SelectMany <T, U, V> (this T? self, Func<T, U?> bind, Func<T, U, V> project ) Source #

where T : struct
where U : struct
where V : struct

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 EitherUnsafe<L, T> toEitherUnsafe <L, T> (T? self, L defaultLeftValue) Source #

where T : struct

method EitherUnsafe<L, T> toEitherUnsafe <L, T> (T? self, Func<L> Left) Source #

where T : struct

method TryOption<T> toTryOption <L, T> (T? self, L defaultLeftValue) Source #

where T : struct

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

where SEMI : struct, Semigroup<T>
where T : struct

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 : Num<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 : Num<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 : Num<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 S fold <S, T> (T? self, S state, Func<S, T, S> folder) Source #

where T : struct

Parameters

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 #

where T : struct

Parameters

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> 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 #