-
Notifications
You must be signed in to change notification settings - Fork 1
FP FP扩展函数
王学懿 edited this page May 11, 2024
·
3 revisions
针对.net中的委托对象(Action
、Func
),扩展出来的FP方法
示例:
//柯里化
int count = 100;
Action<int, int> process = (t1, t2) => count = t1 + t2 + count;
Func<int, Action<int>> curry=process.Currying();
Action<int> result = curry(10);
result(10);//等于120
//分部-逆向柯里化
Action<int, int> result = curry.Partial();
result(10, 10);//等于120
//管道
unc<string, string> result = strToInt
.Pipe(intToDouble)
.Pipe(doubleToStr);
result("10");//绕了一圈最后输出"10"
支持的扩展函数有非常多,并且都有重载,具体的可以用F12
查看定义
函数 | 作用 |
---|---|
Pipe | 管道,支持Action和Func之间,相同类型、不同类型的相互Pipe |
[弃]Do | 作用和Pipe系列一样,所以不再维护一套 |
Currying | 柯里化,将普通函数转换为高阶函数 |
Partial | 分部,将高阶函数转换为普通函数 |