I want to implement filtering function generator in 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
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 .
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)
. Where f
if flip filter
and g
is propEq
Tool would produce (. g) . (.) . f
(. g) . (.) . f
Then you convert this back to javascript to make future maintainer cry. Demo .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.