I'm feeling my way though functional programming with Ramda and I'm struggling on something sounds like it should be easy.
I want all the entries in an array where a property does not equal a value.
For example in pure js
const filtered = source.filter(entry => entry.name !== 'something');
In Ramda there is a propEq
so I can easily get all the elements that do match a value such as
const filtered = R.filter(R.propEq('name','something'),source);
But I can't see how to do the inverse of that, to only return values that do not equal a value.
I'm sure this must be very easy but I'm struggling to see a built in function to do it, the closest I can come up with is:
const others = R.filter(rate => rate.name !== name,res.rates);
But I'm sure there must be a better way?
Ramda is a JavaScript library that makes functional programming simple. While JavaScript libraries with functional capabilities have been around for a while, Ramda acts as a complete standard library specifically catered to the functional paradigm. Ramda is a JavaScript library that makes functional programming simple.
compose FunctionPerforms right-to-left function composition. The rightmost function may have any arity; the remaining functions must be unary. See also pipe.
What makes Ramda great is that their functions are automatically curried, which allows us to quickly build up sequences of small and straightforward functions or old functions that we already have created.
Ramda is generally a better approach for functional programming as it was designed for this and has a community established in this sense. Lodash is generally better otherwise when needing specific functions (esp. debounce ).
Yes, Ramda has a reverse of filter
called reject
:
R.reject(R.propEq('name', 'something'))(source)
You can see this on the Ramda REPL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With