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,42 +1,42 @@
|
||||
namespace SJK.Functional;
|
||||
// namespace SJK.Functional;
|
||||
|
||||
public sealed class Left<TLeft, TRight> : IEither<TLeft, TRight>
|
||||
{
|
||||
private readonly TLeft _value;
|
||||
public Left(TLeft value){
|
||||
this._value = value;
|
||||
}
|
||||
// public sealed class Left<TLeft, TRight> : IEither<TLeft, TRight>
|
||||
// {
|
||||
// private readonly TLeft _value;
|
||||
// public Left(TLeft value){
|
||||
// this._value = value;
|
||||
// }
|
||||
|
||||
|
||||
public IEither<TLeft, T2> Bind<T2>(Func<TRight, IEither<TLeft, T2>> value)
|
||||
{
|
||||
return new Left<TLeft,T2>(_value);
|
||||
}
|
||||
// public IEither<TLeft, T2> Bind<T2>(Func<TRight, IEither<TLeft, T2>> value)
|
||||
// {
|
||||
// return new Left<TLeft,T2>(_value);
|
||||
// }
|
||||
|
||||
public (TLeft?, TRight?) Deconstruct()=>(_value,default(TRight));
|
||||
// public (TLeft?, TRight?) Deconstruct()=>(_value,default(TRight));
|
||||
|
||||
public bool IsRight() => true;
|
||||
// public bool IsRight() => true;
|
||||
|
||||
public IEither<TNewLeft, TRight> MapLeft<TNewLeft>(Func<TLeft, TNewLeft> mapping)
|
||||
=> new Left<TNewLeft,TRight>(mapping(this._value));
|
||||
// public IEither<TNewLeft, TRight> MapLeft<TNewLeft>(Func<TLeft, TNewLeft> mapping)
|
||||
// => new Left<TNewLeft,TRight>(mapping(this._value));
|
||||
|
||||
public IEither<TLeft, TNewRight> MapRight<TNewRight>(Func<TRight, TNewRight> mapping)
|
||||
=> new Left<TLeft,TNewRight>(this._value);
|
||||
// public IEither<TLeft, TNewRight> MapRight<TNewRight>(Func<TRight, TNewRight> mapping)
|
||||
// => new Left<TLeft,TNewRight>(this._value);
|
||||
|
||||
|
||||
public TResult Match<TResult>(Func<TLeft, TResult> left, Func<TRight, TResult> right)
|
||||
{
|
||||
return left(_value);
|
||||
}
|
||||
// public TResult Match<TResult>(Func<TLeft, TResult> left, Func<TRight, TResult> right)
|
||||
// {
|
||||
// return left(_value);
|
||||
// }
|
||||
|
||||
public void Match(Action<TLeft> left, Action<TRight> right)
|
||||
{
|
||||
left(_value);
|
||||
}
|
||||
// public void Match(Action<TLeft> left, Action<TRight> right)
|
||||
// {
|
||||
// left(_value);
|
||||
// }
|
||||
|
||||
public TLeft Reduce(Func<TRight, TLeft> mapping)=> _value;
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Left<{typeof(TLeft).Name}> with Value {_value}";
|
||||
}
|
||||
}
|
||||
// public TLeft Reduce(Func<TRight, TLeft> mapping)=> _value;
|
||||
// public override string ToString()
|
||||
// {
|
||||
// return $"Left<{typeof(TLeft).Name}> with Value {_value}";
|
||||
// }
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user