The Hard Parts of Functional JavaScript

Pure Functions & Immutability Review

Will Sentance

Will Sentance

The Hard Parts of Functional JavaScript

Check out a free preview of the full The Hard Parts of Functional JavaScript course

The "Pure Functions & Immutability Review" Lesson is part of the full, The Hard Parts of Functional JavaScript course featured in this preview video. Here's what you'd learn in this lesson:

Will reviews function purity and immutability, describes function arity, specifically the side effects of function chaining, there could be a mismatch in the amount of arguments a function can take, and explains briefly that closure is the solution to the arity issue.


Transcript from the "Pure Functions & Immutability Review" Lesson

>> Speaker 1: If your array you're passing into map is not scalar values, right? Zero with index is actually an array. Our naive implementation of this that we did earlier would modify that array inside of there thereby modifying [INAUDIBLE]
>> Will Sentance: Have a look and play with it. It's a very legitimate thing to raise.

Have a look and play with it, absolutely. Alex, you're good? All right, folk, I think at this point here, with just one final closing words here. So, pure functions and immutability. Easier to add feature is very fair point from itself. But, that's where we had to be smart about this and understand that pause by reference somebody.

Pure functions and immutability, easier to add features every save function can be safely used in new combinations. Take those, use them anywhere else, knowing that it will not break other parts of our app, more readable. Every line is self contained and complete. I like that word complete, like is when its beginning and ending, everything's in that line.

It's fully descriptive and makes it more readable like I don't need to look at this line and go. Hold on. What is this really doing? I can read it and know that is its beginning and end. And by the way, its end is a certain the next line, and only the next line.

Always, as a strict rule. Exactly what it does is discovered by its name unlimited that empowers as I said it. I just write these from my easily bug know thousands of lines of interdependence. That's what you want to mean by interdependence, every line depend on each other. Each other not directly, but via global states, global memory, global safe data, which can all depend on each other.

I can use this anywhere else. So please don't make this line. No one should not make this line dependent, which can be your implicitly making all other lines dependent on that array. This one line here array don't matter if you were to mutate. So if you had a mutating version of map, it would make all other lines dependent on it.

Map to be clear, is smart. Brand new data, do not mutate. Focus on immutability of data. All right, people, pair programming at this point. And after that, just so you know, we're going cuz I'm really excited where we're going. Seth's question. He said, hold on, my listing of a functions ain't gonna work you've got, you know what they call mismatch RRT.

RRT is a number of inputs your function takes and it's mismatch with a number of inputs. Your use of it's going to expect, it would break the whole thing. Do not fear. We're going to use closure to give our functions the most important superpower. We're then going to be able to decorate functions which is a quick way of editing functions.

So that we don't have to build brand new functions. And giving them special properties that if we save more ready, we can otherwise give them. And it's gonna allow us to achieve partial application that allows us to edit functions, number of inputs.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now