I have a method which requires multiple arguments, and I am trying to set up a ramda pipe to handle it.
Here's an example:
const R = require('ramda');
const input = [
{ data: { number: 'v01', attached: [ 't01' ] } },
{ data: { number: 'v02', attached: [ 't02' ] } },
{ data: { number: 'v03', attached: [ 't03' ] } },
]
const method = R.curry((number, array) => {
return R.pipe(
R.pluck('data'),
R.find(x => x.number === number),
R.prop('attached'),
R.head
)(array)
})
method('v02', input)
Is there a cleaner way of doing this, especially the x => x.number === number
part of filter
and having to call (array)
at the end of the pipe?
Here's a link to the code above loaded into the ramda repl.
One way this could possibly be rewritten:
Here we've replaced the use of
R.pluck
and the anonymous function given toR.find
withR.pathEq
given as the predicate toR.find
instead. Once found, the value can be retrieved by walking down the properties of the object withR.path
.It is possible to rewrite this in a point-free manner using
R.useWith
, though I feel readability gets lost in the process.