FAQ: Core Concepts in Redux - Immutable Updates and Pure Functions

This community-built FAQ covers the “Immutable Updates and Pure Functions” exercise from the lesson “Core Concepts in Redux”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Redux

FAQs on the exercise Immutable Updates and Pure Functions

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in Language Help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to Language Help and Tips and Resources. If you are wanting feedback or inspiration for a project, check out Projects.

Looking for motivation to keep learning? Join our wider discussions in Community

Learn more about how to use this guide.

Found a bug? Report it online, or post in Bug Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Can anyone explain this exercise (Immutable Updates and Pure Functions)?

1 Like

Pure Functions are too pure for this world :globe_with_meridians: ? Kidding…

Was in the same boat as you because the that was too much of an info dump to read through. This video seems to explain it in a friendly sort of way.

5 Likes

I watched the video on object destructuring (sp?) because even though I read the documentation on the spread mentioned by CC in two lessons (probably) before this one I was like its the yadda yadda/ ect… operator !!! This totally clears it up and I think neatly explains what else what in the exercises info dump.

3 Likes

yeah after spending some more time on the exercise after finding the helpful tutorials… This is not the best designed exercise and I think is possibly a bit to steep of a curve to expect. Might need a rework. There are far too many leaps forward. Not typical of CC.

4 Likes

This guy has pretty much got me through this

5 Likes

This guy has gotten me through the worst parts of the full stack course; React and hopefully now Redux as well…
They’re updating the courses on this Friday the 11th, including React. Hoping for some actual working lessons.

3 Likes

I K R !! It’s great if ever the CC explanation is too let’s say text dense I can always YouTube my problem away.

1 Like

Why is reading from a file considered a side effect? Everytime you provide a file as an input to this function, it will read it the same and produce the same output won’t it?

const capitalizeMessage = (file) => {
  const message = fs.readFileSync(file, 'utf8');
  return message.toUpperCase();
}

So I’m not sure why this is not considered a pure function

1 Like

Yeah I’m having a hard time with this, too.

I think the issue is the same as one of the previous exercises where an endpoint was called in the reducer: fs is technically an API, part of Node.js.

So it’s impure because the code is actually relying on an outside library to work, and therefore has some restrictions on when it would run properly.

Also, maybe for some reason it wouldn’t run every time you called it, even with the same file? But in this narrowest sense, I would be tempted to call it a pure function.

But in the larger context, you could definitely break this reducer because surely there are some files you could input that the method wouldn’t be able to read. So that way it’s not pure.

There are definitely easier examples they could use for an impure function due to an external dependency :grin:

1 Like