You Don't Know JS
- 00:00 - 08:37 Course Introduction Kyle Simpson (@getify) begins his course on Functional Lite Programming with a brief introduction of himself. He also shares a few of his more popular open source projects like LabJS, Grips, and Asynquence.
- 08:38 - 16:10 Course Agenda Before jumping into the course, Kyle walks through the agenda. He will begin with higher-level concepts like Composition, Immutability, and Closures. Then the course will move into list-specific operations including the use of map(), filter(), reduce, and forEach().
- 16:11 - 25:46 Side Effects Pure functions are at the heart of functional programming. The first step in learning how to write pure functions is to understand what makes a function impure or have side effects. For example, a function that alters variables outside of its scope is an impure function.
- 25:47 - 27:35 Exercise 1 In this exercise, you will create a pure function named “bar” to wrap around the function “foo”.
- 27:36 - 34:44 Exercise 1 Solution Part 1 Kyle walks through the solution to exercise 1.
- 34:45 - 43:18 Exercise 1 Solution Part 2 Now that Kyle has finished demonstrating the solution to exercise 1, he spends a few minutes answering some audience questions.
Composition & Immutability
- 43:19 - 47:31 Manual Composition Composition involves taking the output from one function and directly inputting it into another function. Kyle demonstrates how composition can be created manually by calling a function within the parameter list of another function. He also shows how to create a manual composition by writing a separate function.
- 47:32 - 55:04 Composition Utility Manually creating compositions can be cumbersome if there are many situations where functions need to be combined. Kyle explains how to create a compose2() function that will take two functions as arguments and return a composition.
- 55:05 - 01:01:50 Immutability To a functional programmer, immutability refers to a variables ability to be changed. Kyle illustrates this by explaining the difference between using the “const” keyword and using Object.freeze().
- 01:01:51 - 01:10:56 Questions on Immutability Kyle spends a few minutes answering audience questions on Immutability. He also talks about implementing a function that returns a copy of an Array as a way to remain pure while working with Array values.
Closure & Recursion
- 01:10:57 - 01:17:24 Closure Closure is when a function “remembers” the variables around it even when that function is executed elsewhere. While using closure is a very powerful technique, side-effects can be produced. Kyle demonstrates this and explains how closure can be written in a more pure way.
- 01:17:25 - 01:18:36 Exercise 2 In this exercise, you will use closure to define a foo() function that returns a function. This returned function remembers only the first two arguments that were passed to foo() and always adds them together.
- 01:18:37 - 01:20:35 Exercise 2 Solution Kyle walks through the solution to exercise 2.
- 01:20:36 - 01:32:58 Recursion Recursion occurs when a function calls itself to perform an operation. A recursive function will continue to call itself until a base case is reached. Kyle introduces this concept and shares some thoughts on its perceived complexity.
- 01:32:59 - 01:36:54 Recursive Example Using a function that sums three numbers as an example, Kyle demonstrates how to take a non-recursive operation and add recursion. He also shows a cleaner version of the recursive function which utilizes ES6 syntax.
- 01:36:55 - 01:37:57 Exercise 3 In this exercise, you will turn the mult() function into a recursive function that can work on as many arguments as necessary.
- 01:37:58 - 01:42:29 Exercise 3 Solution Kyle walks through the solution to exercise 3.
- 01:42:30 - 01:54:28 List Transformation Transforming a list involves performing an operation on every value in that list. Kyle introduces the Array.map() method and explains how it can be used to create immutable list transformations. The new list of transformed values has a one-to-one “mapping” with the original list.
- 01:54:29 - 02:01:57 List Exclusion The Array.filter() method is used to create list exclusions. Each item in the list is passed to a function which returns a boolean value representing whether that item should be included in the list or not. A new list of these filtered items is returned, leaving the original list unmodified.
- 02:01:58 - 02:11:15 List Composition List compositions are created using the Array.reduce() method. Just like the map() method, reduce() iterates through a list performing a transformation on each value. The difference is an initial value is also passed which the items are composed onto creating a smaller, “reduced” list or even a single return value.
- 02:11:16 - 02:14:49 List Iteration List iteration is performed by using the Arrach.forEach() method to loop through list items. Function programmers typically avoid this method since most list iteration use-cases include side effects. Kyle spends a few minutes discussing the list iteration implementation and explains this difference between using forEach() and map().
- 02:14:50 - 02:20:22 Exercise 4 In this multi-part exercise, you will combine a number of the concepts learned throughout this course. Before starting the exercise, Kyle shares a few observations about the process of learning functional programming.
- 02:20:23 - 02:27:29 Exercise 4 Solution Part 1 Kyle begins walking through the solution to exercise 4. First he creates an add() function that will add two numbers. He then creates an add2() function that takes two functions instead of two numbers, calls each function, and sends those values to the add() function.
- 02:27:30 - 02:39:03 Exercise 4 Solution Part 2 Kyle continues his demonstration of the solution to exercise 4. He creates an addn() function that takes an array of values and adds them together using the add2() function.
- 02:39:04 - 02:50:15 Exercise 4 Solution Part 3 Building off the previous solution, Kyle changes the addn() function to now work with an array of functions instead of an array of values. This allows him to incorporate the reduce() method.
- 02:50:16 - 02:56:47 Exercise 4 Solution Part 4 Kyle spends a few minutes answering audience questions. He then continues the solution to exercise 4 by using the map() method so an array of individual values can be passed to addn() as an array of functions.
- 02:56:48 - 03:04:57 Exercise 4 Solution Part 5 The last step in the exercise 4 solution is to incorporate the filter() method so only odd or even values can be passed to addn().
- 03:04:58 - 03:10:26 Wrap Up Kyle wraps up the course with a review of the “Functional Lite” concepts he covered and some of his own thoughts on functional programming in general.