
函数式编程
@kolalo
这个作者很懒,什么都没留下…
展开
-
C# FP Maybe
using System;namespace S{ public struct Option<T> { readonly bool isSome; readonly T value; private Option(T value) { this.value = value; isSome = true; } /// <sum原创 2020-11-23 22:50:15 · 160 阅读 · 0 评论 -
C# Func与Predicate互转
public static Predicate<T> FuncToPredicate<T>(this Func<T, bool> func){ return x => func(x);}public static Func<T, bool> PredicateToFunc<T>(this Predicate<T> predicate){ return x => predicate(x);}原创 2020-11-22 22:12:39 · 284 阅读 · 0 评论 -
C# Action转换为Func
在使用FP编码的过程中会遇到这样一个问题:A函数需要传入一个Func参数来执行,后来由于某种需要,对A函数进行重载,重载后的A函数只是传入的参数由Func变成了Action其他的基本都没发生变化,这样会产生两套一样的代码,解决方案如下:using Unit = System.ValueType;public static class ActionToFunc{ private static Unit Unit() => default(Unit); public static原创 2020-11-22 21:28:57 · 328 阅读 · 0 评论 -
C# FP Unit
在使用FP编码的过程中会遇到这样一个问题:A函数需要传入一个Func参数来执行,后来由于某种需要,对A函数进行重载,重载后的A函数只是传入的参数由Func变成了Action其他的基本都没发生变化,这样会产生两套一样的代码,解决方案如下:using Unit = System.ValueType;public static class ActionToFunc{ private static Unit Unit() => default(Unit); public static原创 2020-11-22 21:23:36 · 277 阅读 · 0 评论 -
C# 函数柯里化
柯里化(局部套用)定义:是把接受多个参数的函数变换成接受一个单一参数(最初函数的第一个参数)的函数,并且返回接受余下的参数且返回结果的新函数的技术。public static class A{ public static Func<T1, Func<T2, TResult>> Currying<T1, T2, TResult>(this Func<T1, T2, TResult> func) => x1 => x2 => func原创 2020-10-15 18:35:00 · 464 阅读 · 0 评论