-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
currying #45
Labels
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
函数柯里化又叫部分求值,维基百科中对柯里化 (Currying) 的定义为:
简单来说,柯里化其实就是一个参数收集的过程,将每一次传入的参数收集起来,然后在最里层再进行处理。
所以一个合格的柯里化函数需要这么几点:
其实上文所实现的功能就类似于延迟计算,但是有个缺点:
sum(1, 2, 3)(4, 5)(6)()
另一种更通用的柯里化:
这样我们就实现了一个通用柯里化,实现原理就是「用闭包把传入参数保存起来,当传入参数的数量足够执行函数时,就开始执行函数」。比刚才的延迟计算类型的柯里化更完善一点。
但是我一直很疑惑一点,后者其实会被初始函数的形参个数限定死,万一碰到初始函数形参个数不定的呢?(:з」∠)
The text was updated successfully, but these errors were encountered: