简体   繁体   English

将 compose 与多个函数和内部 function 与参数一起使用

[英]Use compose with several functions and inner function with param

I have the following:我有以下内容:

 { reseller: filterOutNonUsable(dedupe(extractArrVals(data.locks.entries, 'reseller'))) }

What is the best way to call all these functions and use a second parameter for the extractArrVals function (see my example) so that I can use https://www.30secondsofcode.org/snippet/compose ?调用所有这些函数并为 extractArrVals function 使用第二个参数的最佳方法是什么(请参阅我的示例),以便我可以使用https://www.30secondsofcode.org/snippet/compose

const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));

const extractArrVals = (obj, key) => {
  /////YOUR FUNCTION
};

const dedupe = (data) => {
  /////YOUR FUNCTION
}

const filterOutNonUsable = (data) => {
  /////YOUR FUNCTION
}

// transformer or whatever it's name
const transformer = compose(
  filterOutNonUsable,
  dedupe,
  extractArrVals
);

transformer(data.locks.entries, 'reseller')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM