Table of Contents
IntroductionAnjana Vakil walks through the outline and provides links to the slides and exercises for the course. All exercises are hosted on Observable HQ and can be coded in the browser.
What is Functional Programming
What is Functional ProgrammingAnjana describes functional programming as having a specific mindset when writing code and compares it to other paradigms like imperative programming or object-oriented programming. A core concept of functional programming is the use of pure functions which are functions that do not produce side effects.
Pure vs Impure FunctionsAnjana compares two functions to highlight the differences between pure and impure functions. A pure function is deterministic which means when given a specific input, the output will always be the same.
Side EffectsAnjana demonstrates how to remove side effects from an impure function. Side effects are produced any time a function depends on or manipulates data outside of itself. Pure functions do nothing but return output based on an input.
Pure Functions ExerciseStudents are instructed to decide whether each function is pure or impure.
Pure Functions SolutionAnjana demonstrates the solution to the Pure Functions exercise.
Staying out of the Loop with Recursion
RecursionAnjana explains iterative loops are not a part of functional programming and demonstrates how a for loop can be refactored to use recursion. When a function is recursive, it continues to call itself until a non-recursive base case is reached.
Iteration vs Recursion ExerciseStudents are instructed to compare iterative and recursive functions for their readability, writability, and performance.
Iteration vs Recursion SolutionAnjana demonstrates the solution to the Iteration vs Recursion exercise.
HIgher Order Functions
filter, map, & reduce ExerciseStudents are instructed create predicate functions that can be used with the filter function, implement a map function, and create "sum" and "max" reducer functions.
filter, map, & reduce Solution: filterAnjana demonstrates the solution to the filter, map & reduce exercise. This segment covers implementing predicate functions for the filter function.
filter, map, & reduce Solution: mapAnjana demonstrates the solution to the filter, map & reduce exercise. This segment covers implementing the map function.
filter, map, & reduce Solution: reduceAnjana demonstrates the solution to the filter, map & reduce exercise. This segment covers implementing the sum and max reducer functions.
ClosureAnjana describes that closure occurs when a function defined inside another function retains access to scope from the outer function's body. This allows the inner function to access data that was not explicitly passed to it as an argument.
Partial Application & CurryingAnjana explains partially applied functions have some arguments "locked in" by using a closure. Currying is the process of refactoring a single function with multiple arguments to a series of partially applied functions.
Closure & Currying ExerciseStudents are instructed to create two functions that return closures and curry another function to make it more reusable.
Closure & Currying SolutionAnjana demonstrates the solution to the Closure & Currying exercise.
Function CompositionAnjana explains how functional programers use functional composition to create full programs. One function's output becomes the input for another function. The program itself is a function composed from other smaller functions.
Function Composition ExerciseStudents are instructed to write a pipeline function that receives a series of functions as input and then use the pipeline technique to convert strings from snake_case to camelCase.
Function Composition SolutionAnjana demonstrates the solution to the Function Composition exercise.
ImmutabilityAnjana demonstrates how to use the map function to copy an array to prevent mutation. Although the new copy has prevented mutating the original Array, creating copies can increase the amount of memory required to run a program. Immutable or persistent data structures allow unchanged parts of the data to be reused throughout a program.
Avoiding Mutation ExerciseStudents are instructed to rewrite the mutable push and pop Array methods and experiment with the Immutable.js and Immer libraries.
Avoiding Mutation SolutionAnjana demonstrates the solution to the Avoiding Mutation exercise.