I want to apply different functions to some object properties. Lets say I have this object:
const person = {
name: 'John',
age: 30,
friends: [],
};
and i have some functions that i want to apply to those properties:
const upperCase = str => str.toUpperCase() //for the name
const add10 = int => int + 10 // for the age
const addFriend = (value,list) => [...list,value] // adding a friend
and this should be the result:
const person = {
name: 'JOHN',
age: 40,
friends: ['Lucas']
}
What is the best way to achieve this using functional programming and point free, and if you could include examples using Ramda I would appreciate it, Thanks!
With Ramda, you're looking at the
evolve
function:You probably need to define "transform" functions on the fly; I bet you don't want to add 'Lucas' as a friend of every single person. Hopefully this is enough to get you started.
Point-free style is not the only way
⚠️
Please note that I've been able to implement this point-free style because I could hardcode each transformation functions. If you need to craft a transformation object on the fly, doing so point-free style is likely to be unreadable quickly.