Another way to do this, without dots and preserving the existing API, is as follows:
// getLocalDeps :: [{ source :: { value :: String }}] -> RegExp -> [String] const getLocalDeps = R.useWith( R.flip(R.call), R.map(R.path(['source', 'value'])), R.pipe(R.unary(R.test), R.filter) ); localDeps(items, localRegex); //=> ["./foo"]
The last line of the function seems a little unsuccessful to me, and this question made me open the question of returning some recent changes to the library. There are several options:
or
But until the recent change in Ramda, that would be simple.
However, one thing is that Ramda is trying to keep the parameters in a logical order: those who are less likely to change before they are more likely to change. With that in mind, I would prefer something like this:
// getLocalDeps :: RegExp -> [{ source :: { value :: String }}] -> [String] var getLocalDeps2 = R.useWith( R.call, R.pipe(R.unary(R.test), R.filter), R.map(R.path(['source', 'value'])) ); localDeps2(localRegex, items); //=> ["./foo"]
And it's even cleaner. In addition, it allows you to predefine a function and use it separately:
myDeps = localDeps2(localRegex); myDeps(items); //=> ["./foo"]
And this is a good part of what Ramda is talking about.
Scott Sauyet
source share