使用全局命名空间
This commit is contained in:
parent
198607f4ef
commit
eec4cbc3b6
|
@ -1,5 +1,3 @@
|
|||
using Sanchime.Functional.Products;
|
||||
|
||||
namespace Sanchime.Functional.Extensions;
|
||||
|
||||
public static class ActionExtension
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
using Sanchime.Functional.Products;
|
||||
|
||||
namespace Sanchime.Functional.Extensions;
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
using Sanchime.Functional.Products;
|
||||
|
||||
namespace Sanchime.Functional.Extensions;
|
||||
|
||||
public static class EitherExtension
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
using Sanchime.Functional.Products;
|
||||
|
||||
namespace Sanchime.Functional.Extensions;
|
||||
|
||||
public static class EnumExtension
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
using Sanchime.Functional.Products;
|
||||
|
||||
namespace Sanchime.Functional.Extensions;
|
||||
|
||||
/// <summary>
|
||||
|
@ -10,6 +8,29 @@ public static class ExceptionalException
|
|||
public static Func<T, Exceptional<T>> Return<T>()
|
||||
=> val => val;
|
||||
|
||||
public static Unit Match<T>(this Exceptional<T> @this, Action<Exception> Exception, Action<T> Success)
|
||||
=> @this.Match(Exception.ToFunc(), Success.ToFunc());
|
||||
|
||||
#region 函子
|
||||
|
||||
public static Exceptional<R> Map<T, R>(this Exceptional<T> @this, Func<T, R> mapping)
|
||||
=> @this.Successful ? mapping(@this.Value) : new Exceptional<R>(@this.Exception);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 应用式
|
||||
|
||||
public static Exceptional<R> Apply<T, R>(this Exceptional<Func<T, R>> @this, Exceptional<T> value)
|
||||
=> @this.Match(
|
||||
Exception: e => e,
|
||||
Success: apply => value.Match(
|
||||
Exception: e => e,
|
||||
Success: val => new Exceptional<R>(apply(val))
|
||||
)
|
||||
);
|
||||
|
||||
public static Exceptional<Func<T2, R>> Apply<T1, T2, R>(this Exceptional<Func<T1, T2, R>> @this, Exceptional<T1> value)
|
||||
=> @this.Map(CurryingExtension.Curry).Apply(value);
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
using Sanchime.Functional.Products;
|
||||
namespace Sanchime.Functional.Extensions;
|
||||
|
||||
public static class FuncExtension
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
global using Sanchime.Functional.Products;
|
||||
|
||||
namespace Sanchime.Functional.Extensions;
|
|
@ -1,5 +1,4 @@
|
|||
using System.Collections.Immutable;
|
||||
using Sanchime.Functional.Products;
|
||||
|
||||
namespace Sanchime.Functional.Extensions;
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
using Sanchime.Functional.Products;
|
||||
|
||||
namespace Sanchime.Functional.Extensions;
|
||||
|
||||
public static class IdentityExtension
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
using Sanchime.Functional.Products;
|
||||
|
||||
namespace Sanchime.Functional.Extensions;
|
||||
|
||||
public static class NullableExtension
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
using Sanchime.Functional.Products;
|
||||
|
||||
namespace Sanchime.Functional.Extensions;
|
||||
|
||||
public static class OptionExtension
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Sanchime.Functional.Products;
|
||||
namespace Sanchime.Functional.Extensions;
|
||||
|
||||
public static class TaskExtension
|
||||
|
|
|
@ -2,13 +2,13 @@ namespace Sanchime.Functional.Products;
|
|||
|
||||
public readonly struct Exceptional<TValue>
|
||||
{
|
||||
internal Exception _exception { get; }
|
||||
internal Exception Exception { get; }
|
||||
|
||||
internal TValue _value { get; }
|
||||
internal TValue Value { get; }
|
||||
|
||||
public bool Success => _exception is null;
|
||||
public bool Successful => Exception is null;
|
||||
|
||||
public bool Exception => !Success;
|
||||
public bool Exceptionally => !Successful;
|
||||
|
||||
internal Exceptional(Exception exception)
|
||||
{
|
||||
|
@ -16,11 +16,11 @@ public readonly struct Exceptional<TValue>
|
|||
{
|
||||
throw new ArgumentNullException(nameof(exception));
|
||||
}
|
||||
(_exception, _value) = (exception, default!);
|
||||
(Exception, Value) = (exception, default!);
|
||||
}
|
||||
|
||||
internal Exceptional(TValue right)
|
||||
=> (_value, _exception) = (right, default!);
|
||||
=> (Value, Exception) = (right, default!);
|
||||
|
||||
public static implicit operator Exceptional<TValue>(Exception left)
|
||||
=> new(left);
|
||||
|
@ -29,7 +29,7 @@ public readonly struct Exceptional<TValue>
|
|||
=> new(right);
|
||||
|
||||
public TRight Match<TRight>(Func<Exception, TRight> Exception, Func<TValue, TRight> Success)
|
||||
=> this.Exception ? Exception(_exception) : Success(_value);
|
||||
=> Exceptionally ? Exception(this.Exception) : Success(Value);
|
||||
|
||||
public override string ToString()
|
||||
=> Match(e => $"Exception({e.Message})", v => $"Success({v})");
|
||||
|
|
Loading…
Reference in New Issue