[英]Ramda - filtering array of objects - curried fn parameters order
I want to implement filtering function generator in ramda.js. 我想在ramda.js中实现过滤函数生成器。 In my mind, it should works this way: 在我看来,它应该这样运行:
var a = filterFn(arrOfObjects)
var b = a(keyName)
var c = b(value)
It's very imporant to achieve this order of arguments, because the same array could be filtered using different conditions. 实现此顺序的参数非常重要,因为可以使用不同的条件过滤同一数组。
Currently I have the following code: 目前,我有以下代码:
var g = R.curryN(2, R.compose(R.filter(R.__)(R.__), R.propEq))
g('classId')(2)(input)
but I want to have 'input' as first argument: 但我想将“输入”作为第一个参数:
g(input)('classId')(1)
Here is a ramda REPL: code 这是一个ramda REPL: 代码
Thanks in advance! 提前致谢!
I would just use something like this: 我只会用这样的东西:
R.curry((list, name, value) => R.filter(R.propEq(name, value), list));
Ramda does not include an arbitrary parameter-reordering mechanism, just flip
and the __
placeholder . Ramda不包括任意的参数重新排序机制,仅包含flip
和__
占位符 。
You don't really want this function to be pointfree :) 您实际上并不希望此功能没有意义:)
var g = R.compose(
R.curryN(2, R.compose)(R.__, R.propEq),
R.curryN(2, R.compose),
R.flip(R.filter)
)
Or atleast make sure future maintainer would never know where you live :) 或者至少确保未来的维护者永远不会知道您的住所:)
How to get something terrible like this one. 如何获得像这样的可怕的东西。
First, you write pointful version of your function which is straight forward. 首先,编写功能明确的版本。
list => prop => value => R.filter(R.propEq(prop)(value))(list)
or 要么
list => prop => value = R.flip(R.filter)(list)(R.propEq(prop)(value))
Then go to Pointfree.io and use some haskell syntax \\xyz -> fx (gyz)
. 然后转到Pointfree.io并使用一些haskell语法\\xyz -> fx (gyz)
。 Where f
if flip filter
and g
is propEq
其中f
如果flip filter
和g
是propEq
Tool would produce (. g) . (.) . f
工具将产生(. g) . (.) . f
(. g) . (.) . f
Then you convert this back to javascript to make future maintainer cry. 然后,将其转换回javascript,以使将来的维护人员哭泣。 Demo . 演示
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.