namespace MS.Microservice.Core.Functional
{
///
/// 提供偏函数应用与函数柯里化支持。
///
public static partial class F
{
extension(Func func)
{
public Func Map(Func g) => () => g(func());
public Func Bind(Func> g) => () => g(func())();
}
extension(Func func)
{
///
/// 将二元函数转换为一连串一元函数,便于逐个提供参数。
///
public Func> Curry()
=> arg1 => arg2 => func(arg1, arg2);
///
/// 对二元函数先应用第一个参数,返回等待第二个参数的新函数。
///
public Func Apply(T1 arg1)
=> arg2 => func(arg1, arg2);
}
extension(Func func)
{
///
/// 将三元函数转换为一连串一元函数,便于逐个提供参数。
///
public Func>> Curry()
=> arg1 => arg2 => arg3 => func(arg1, arg2, arg3);
///
/// 对三元函数先应用第一个参数,返回等待后续参数的新函数。
///
public Func> Apply(T1 arg1)
=> arg2 => arg3 => func(arg1, arg2, arg3);
}
extension(Func> func)
{
public Func Apply(T1 arg1)
=> func(arg1);
}
extension(Func>> func)
{
public Func> Apply(T1 arg1)
=> func(arg1);
}
public static Func> CurryFirst
(this Func @this) => t1 => (t2, t3) => @this(t1, t2, t3);
public static Func> CurryFirst
(this Func @this) => t1 => (t2, t3, t4) => @this(t1, t2, t3, t4);
public static Func> CurryFirst
(this Func @this) => t1 => (t2, t3, t4, t5) => @this(t1, t2, t3, t4, t5);
public static Func> CurryFirst
(this Func @this) => t1 => (t2, t3, t4, t5, t6) => @this(t1, t2, t3, t4, t5, t6);
public static Func> CurryFirst
(this Func @this) => t1 => (t2, t3, t4, t5, t6, t7) => @this(t1, t2, t3, t4, t5, t6, t7);
public static Func> CurryFirst
(this Func @this) => t1 => (t2, t3, t4, t5, t6, t7, t8) => @this(t1, t2, t3, t4, t5, t6, t7, t8);
public static Func> CurryFirst
(this Func @this) => t1 => (t2, t3, t4, t5, t6, t7, t8, t9) => @this(t1, t2, t3, t4, t5, t6, t7, t8, t9);
}
}