Refactored Option<T> to have opertator lifting and removed ref struct for now.
All checks were successful
Build NuGet / build (push) Successful in 1m43s
All checks were successful
Build NuGet / build (push) Successful in 1m43s
This commit is contained in:
@@ -1,38 +1,38 @@
|
||||
namespace SJK.Functional;
|
||||
// namespace SJK.Functional;
|
||||
|
||||
public sealed class Right<TLeft, TRight> : IEither<TLeft, TRight>
|
||||
{
|
||||
private readonly TRight _value;
|
||||
public Right(TRight value){
|
||||
this._value = value;
|
||||
}
|
||||
public (TLeft?, TRight?) Deconstruct()=>(default(TLeft),_value);
|
||||
public IEither<TNewLeft, TRight> MapLeft<TNewLeft>(Func<TLeft, TNewLeft> mapping)
|
||||
=> new Right<TNewLeft,TRight>(this._value);
|
||||
// public sealed class Right<TLeft, TRight> : IEither<TLeft, TRight>
|
||||
// {
|
||||
// private readonly TRight _value;
|
||||
// public Right(TRight value){
|
||||
// this._value = value;
|
||||
// }
|
||||
// public (TLeft?, TRight?) Deconstruct()=>(default(TLeft),_value);
|
||||
// public IEither<TNewLeft, TRight> MapLeft<TNewLeft>(Func<TLeft, TNewLeft> mapping)
|
||||
// => new Right<TNewLeft,TRight>(this._value);
|
||||
|
||||
public IEither<TLeft, TNewRight> MapRight<TNewRight>(Func<TRight, TNewRight> mapping)
|
||||
=> new Right<TLeft,TNewRight>(mapping(this._value));
|
||||
// public IEither<TLeft, TNewRight> MapRight<TNewRight>(Func<TRight, TNewRight> mapping)
|
||||
// => new Right<TLeft,TNewRight>(mapping(this._value));
|
||||
|
||||
public TLeft Reduce(Func<TRight, TLeft> mapping)=> mapping(this._value);
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Right<{typeof(TRight).Name}> with Value {_value}";
|
||||
}
|
||||
// public TLeft Reduce(Func<TRight, TLeft> mapping)=> mapping(this._value);
|
||||
// public override string ToString()
|
||||
// {
|
||||
// return $"Right<{typeof(TRight).Name}> with Value {_value}";
|
||||
// }
|
||||
|
||||
public TResult Match<TResult>(Func<TLeft, TResult> left, Func<TRight, TResult> right)
|
||||
{
|
||||
return right(_value);
|
||||
}
|
||||
// public TResult Match<TResult>(Func<TLeft, TResult> left, Func<TRight, TResult> right)
|
||||
// {
|
||||
// return right(_value);
|
||||
// }
|
||||
|
||||
public void Match(Action<TLeft> left, Action<TRight> right)
|
||||
{
|
||||
right(_value);
|
||||
}
|
||||
// public void Match(Action<TLeft> left, Action<TRight> right)
|
||||
// {
|
||||
// right(_value);
|
||||
// }
|
||||
|
||||
public IEither<TLeft, T2> Bind< T2>(Func<TRight, IEither<TLeft, T2>> value)
|
||||
{
|
||||
return value(_value);
|
||||
}
|
||||
// public IEither<TLeft, T2> Bind< T2>(Func<TRight, IEither<TLeft, T2>> value)
|
||||
// {
|
||||
// return value(_value);
|
||||
// }
|
||||
|
||||
public bool IsRight() => false;
|
||||
}
|
||||
// public bool IsRight() => false;
|
||||
// }
|
||||
Reference in New Issue
Block a user