Let's see another example with the same order
object as earlier. We want to increment the value of quantity
by 1. How would we go about doing this?
Here we can use the modify
function from Ramda to update the data referring to its previous values as follows:
It can be seen how elegant we can make code by applying all the features of Ramda.
A very important point to keep in mind is that modify
cannot be used to add a new property to an object. This makes sense from the use case of modify
. It is used to assign a new value to a key based on its previous value. If we're adding a new key, it does not have a previous value, hence we would use assoc
or assocPath
for such scenarios.
Let's look at a few more examples of how we can use modify
: