我正在学习Ramda,我有点困惑如何lodash使用Ramda. Ramda返回其操作的函数而不是实际值,这似乎是函数式编程的重点,但是在此示例中,我有第二个参数localRegex不是主要参数。Ramda如果不包装函数并使用.apply()或.call()将包装的函数参数传播给函数,似乎不可能完全复制Ramda它,这似乎比使用更复杂lodash。
var _ = require("lodash")
var R = require("ramda")
var localRegex = /^.\.\/|^.\/|^\//
function getRecursiveDeps(deps, localRegex){
return _.chain(deps)
.map(function(dep){
return dep.source.value
})
.filter(function(dep){
return dep.match(localRegex)
})
.value()
}
var items = [
{
"source": {
"value": "./foo"
}
},
{
"source": {
"value": "bar"
}
}
]
console.log(getRecursiveDeps(items, localRegex))
这就是我所拥有的,但它不起作用。
var getRecursiveDeps = R.chain(
R.map(function(dependency){
return dependency.source.value
}),
R.filter(function(value){
return value.match(localRegex)
})
)
有没有办法Ramda使用主变量进行链接并向下传递localRegex?有没有办法复制使用的getRecursiveDeps那个?lodashRamda
有很多关于Ramda功能性和underscore非功能性的讨论lodash。但在这种情况下,getRecursiveDeps是一个从 中返回值的函数lodash。当您创建这样的函数lodash或underscore结果相同时,在包装它时还有更多工作,在这种情况下,使用Ramdaover会有什么好处Lodash?