The assoc
function is used to set or override the specified property of an object with the given value as shown below:
The assoc
function is also curried like most other Ramda functions. It comes in handy when we use assoc
for state updates in React. Consider the following object is stored in state and we want to update the firstName
attribute:
Here the callback expression is avoided as Ramda returns a curried function that will accept prevUser
as an argument and then execute.
assoc
function creates a new copy of the object. All non-primitive properties are copied by reference.