Skip to content
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

在“代码组合——函数饲养”一节里发现了个错误 #34

Open
wqcstrong opened this issue Dec 25, 2017 · 4 comments
Open

Comments

@wqcstrong
Copy link

...
...
// 前面的例子中我们必须要写两个组合才行,但既然组合是符合结合律的,我们就可以只写一个,
// 而且想传给它多少个函数就传给它多少个,然后让它自己决定如何分组。

var lastUpper = compose(toUpperCase, head, reverse);

lastUpper(['jumpkick', 'roundhouse', 'uppercut']);
//=> 'UPPERCUT'

在上述代码中,我个人计算的和控制台输出的答案都是"JUMPKICK"。还望作者确认一下,不知道到底是我搞错了还是您大意了、

@wqcstrong
Copy link
Author

其实上面的代码我也还有一个问题不是很理解。在调用compose传三个参数的时候,第三个参数在compose函数里面怎么就调到了???

@yjhmelody
Copy link

yjhmelody commented Dec 31, 2017

@wqcstrong 前文定义的compose 只组合2个函数。
所以才输出JUMPKICK啊 并没有使用reverse这个函数。
这里compose是组合任意多个函数的。要么自己写,要么调用lodash或者ramda的compose。

@as02700
Copy link

as02700 commented Feb 8, 2018

compose(toUpperCase, head, reverse)(['jumpkick', 'roundhouse', 'uppercut'])
==
toUpperCase(head(reverse(['jumpkick', 'roundhouse', 'uppercut'])))

@muzimuzhi
Copy link

muzimuzhi commented Sep 27, 2020

其实上面的代码我也还有一个问题不是很理解。在调用compose传三个参数的时候,第三个参数在compose函数里面怎么就调到了???

@wqcstrong 原文已修改为,首先介绍接受任意个参数的 compose 定义,然后从接受两个参数的简化版本开始介绍。见 May 2018 的提交 MostlyAdequate/mostly-adequate-guide@2c8dece

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants