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

改造接口 unary #113

Open
cklwblove opened this issue Dec 20, 2022 · 0 comments
Open

改造接口 unary #113

cklwblove opened this issue Dec 20, 2022 · 0 comments

Comments

@cklwblove
Copy link
Owner

改造函数的接口,一元参数(unary),它的作用是把一个接收多个参数的函数,变成一个只接收一个参数的函数

function unary(fn) {
  return function oneArg(arg) {
      return fn(arg);
  }
}
["1","2","3","4","5"].map( unary( parseInt ) ); // [1,2,3,4,5]

二元就是 binary,或是函数式中的“黑话”dyadic;三元就是 tenary。顾名思义,它们分别代表的就是把一个函数的参数数量控制在 2 个和 3 个。

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

1 participant