DEV Community

Discussion on: Why go functional? A practical example

Collapse
 
jackmellis profile image
Jack

I would say the problem is with user.status = status this is the part where you're mutating an object rather than creating a new one. Regardless of whether that function returns a reference or a clone, the point at which a side effect is introduced is that line.

You can never assume an external function is returning a safe-to-mutate result.

Also you're calling getTaskById instead of getUserById 🙂

Collapse
 
aboutandre profile image
aboutandre

Hi Jack, thanks for getting that typo (that's what happens when you're writing an article in the middle of the night!). The original code was more complicated and was ideed about "tasks" 😉
And you're right on all aspects. My intention is to make devs aware on how we can create code that is more reliable, be as a "consumer" or "producer" of the code.