Class MaybeExtensions
- Namespace
- LfrlAnvil.Functional.Extensions
- Assembly
- LfrlAnvil.Functional.dll
Contains Maybe<T> extension methods.
public static class MaybeExtensions
- Inheritance
-
MaybeExtensions
- Inherited Members
Methods
MatchWith<T1, T2>(Maybe<T1>, Maybe<T2>, Action<T1, T2>, Action<T1>, Action<T2>, Action)
Matches two Maybe<T> instances together and invokes a correct delegate based on which values are set.
public static Nil MatchWith<T1, T2>(this Maybe<T1> source, Maybe<T2> other, Action<T1, T2> both, Action<T1> first, Action<T2> second, Action none) where T1 : notnull where T2 : notnull
Parameters
source
Maybe<T1>First maybe.
other
Maybe<T2>Second maybe.
both
Action<T1, T2>Delegate to invoke when both maybe's have a value.
first
Action<T1>Delegate to invoke when only the first maybe has a value.
second
Action<T2>Delegate to invoke when only the second maybe has a value.
none
ActionDelegate to invoke when none of the maybe's has a value.
Returns
Type Parameters
T1
First maybe's value type.
T2
Second maybe's value type.
MatchWith<T1, T2, T3>(Maybe<T1>, Maybe<T2>, Func<T1, T2, T3>, Func<T1, T3>, Func<T2, T3>, Func<T3>)
Matches two Maybe<T> instances together and invokes a correct delegate based on which values are set.
[Pure]
public static T3 MatchWith<T1, T2, T3>(this Maybe<T1> source, Maybe<T2> other, Func<T1, T2, T3> both, Func<T1, T3> first, Func<T2, T3> second, Func<T3> none) where T1 : notnull where T2 : notnull
Parameters
source
Maybe<T1>First maybe.
other
Maybe<T2>Second maybe.
both
Func<T1, T2, T3>Delegate to invoke when both maybe's have a value.
first
Func<T1, T3>Delegate to invoke when only the first maybe has a value.
second
Func<T2, T3>Delegate to invoke when only the second maybe has a value.
none
Func<T3>Delegate to invoke when none of the maybe's has a value.
Returns
- T3
Result returned by the invoked delegate.
Type Parameters
T1
First maybe's value type.
T2
Second maybe's value type.
T3
Result type.
Reduce<T>(Maybe<Maybe<T>>)
Creates a new Maybe<T> instance.
[Pure]
public static Maybe<T> Reduce<T>(this Maybe<Maybe<T>> source) where T : notnull
Parameters
Returns
Type Parameters
T
Value type.
ToEither<T>(Maybe<T>)
Creates a new Either<T1, T2> instance with Nil second type.
[Pure]
public static Either<T, Nil> ToEither<T>(this Maybe<T> source) where T : notnull
Parameters
source
Maybe<T>Source maybe.
Returns
- Either<T, Nil>
New Either<T1, T2> instance equivalent to the provided
source
or Nil whensource
does not have a value.
Type Parameters
T
Value type.