Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 函数式编程无点多参数_Javascript_Functional Programming_Pointfree - Fatal编程技术网

Javascript 函数式编程无点多参数

Javascript 函数式编程无点多参数,javascript,functional-programming,pointfree,Javascript,Functional Programming,Pointfree,假设我已经有了count、split和pipe函数。 我有管道功能: const pipe = (f1, ...fns) => (...args) => { return fns.reduce((res, fn) => fn(res), f1.apply(null,args)); }; const getLen = str => count(split('', str)) 这是常规功能: const pipe = (f1, ...fns) => (...ar

假设我已经有了count、split和pipe函数。 我有管道功能:

const pipe = (f1, ...fns) => (...args) => {
  return fns.reduce((res, fn) => fn(res), f1.apply(null,args));
};
const getLen = str => count(split('', str))
这是常规功能:

const pipe = (f1, ...fns) => (...args) => {
  return fns.reduce((res, fn) => fn(res), f1.apply(null,args));
};
const getLen = str => count(split('', str))
这是无点函数

const getLen = pipe(split(''), count)
是否有任何方法使其适用于多个参数

例如,我有一个范围函数(注意,它是自动转换的():

如何使返回范围和的函数成为无点函数

const getSum = pipe(
   range(), // i dont know how to get parameters if its pointfree
   sum
)

管道是一元函数或一个参数函数的组合。没有办法对参数以上的函数进行管道传输,因为您将获得一个输入并将输出提供给下一个函数,依此类推

因此,如果要使用
范围
,首先需要提供
from
参数:

const getSum = pipe(
   range(1),
   sum
)

换句话说,您可以使用多个参数的函数,但需要使用部分应用程序来获得所需的输出。没有参数的
range
是没有问题的,但是结果是一个部分应用程序,它不是你所期望的
pipe
的输出。

getLen=pipe(split(“”),count)
你看起来完全忽略了
str
?是的,管道会将参数传递到拆分,然后传递到countSo
pipe
是一个返回函数的函数,是吗?你能分享一下吗?(你能修改它吗?)它与文章中的功能类似<代码>类似<代码>如何使用它对你的问题至关重要,请在你的问题中发布它(不要强迫人们试图帮助去外部网站了解你在做什么)