Table of Contents
Functional Programming Introduction
Functional ProgrammingKyle discusses why learning Functional Programming (FP) is essential to becoming a better programmer. FP is the process of building software by composing pure functions, avoiding shared state, mutable data, and side-effects. Functional programming is declarative rather than imperative, and application state flows through pure functions. Declarative code focuses on what happens while Imperative code is focusing how something should happen.
Provable and ReadableKyle explains that writing code that you don't understand is code that you cannot trust and vice versa. By using Functional Programming through mathematically proven patterns, programmers can trust their code. Kyle takes questions from students about abstraction.
Pure Functions and Side-EffectsUnderscoring pure functions are at the heart of functional programming, Kyle states that 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.
Purifying FunctionsKyle reviews how to purify a function removing side effects, but the tradeoffs include pragmatic approach.
Challenge 1: Purify a FunctionIn this challenge, students purify a function by creating a pure function named “bar” to wrap around the function “foo.”
Challenge 1: SolutionKyle walks through the solution to Challenge 1.
Evolving Understanding of ImpurityAfter the exercise, Kyle continues to explore the potential pitfalls of coding pure functions and judging its purity relies on the context of the application.
Managing Function Inputs
ArgumentsThe order of arguments matter, Spreading Properties
No PointsKyle reviews tacit programming or "point-free" style as it is commonly called. The term "point" refers to a function's parameter.
Challenge 2: Point-Free StyleIn this challenge, students refactor functions into point-free style.
Challenge 2: SolutionKyle walks through the solution to Challenge 2.
Composition IntroductionFunctions come in different shapes and sizes, Kyle illustrates how to combine functions to make a new compound function as a utlitilty in various parts of a program. This method of using functions in this manner is called composition.
Challenge 3: Compose and Pipe UtilityIn this challenge, students code their own compose and pipe utilitiy.
Challenge 3: SolutionKyle walks through the solution to Challenge 3.
Immutability IntroductionTo a functional programmer, Kyle explains that immutability refers to a variable's ability to be changed. Kyle illustrates this by explaining the difference between using the “const” keyword and using Object.freeze().
Challenge 4: Compose and PipeIn this challenge, students code their own compose and pipe utilitiy.
Challenge 4: SolutionKyle walks through the solution to Challenge 4.
Closure and Side EffectsKyle reviews closure, which is when a function "remembers" the variables around it even when that function is executed elsewhere. While using closure is a very powerful technique, Kyle demonstrates that side-effects can be produced and how closure can be written in a more pure way.
Challenge 5: Purifying ClosureIn this challenge, students rewrite a closure to be more pure.
Challenge 5: SolutionKyle walks through the solution to Challenge 5 and takes questions from students.
Generalized to SpecializedKyle demonstrates using partials as a technique to specialize a generalized function. Then Kyle shows that currying, while a similar technique, is where a function that expects multiple arguments is broken down into successive chained functions that each take a single argument.
Recursion IntroductionKyle introduces the concept of recursion, which is when a function calls itself to perform an operation and it will continue to call itself until a base case is reached.
Challenge 6: Recursive OperationIn this challenge, students take create a recursive operation.
Challenge 6: SolutionKyle walks through the solution to Challenge 6.
Proper Tail CallsKyle reviews Proper Tail Calls (PTC). A tail call occurs when a function calls another as its last action, so it has nothing else to do. A PTC does not need any extra stack space when doing a tail call.
Continuation Passing StyleKyle illustrates Continuation Passing Style (CPS), which is organizing code so that each function receives another function to execute at its end.
TrampolinesIn demonstrating trampolines, Kyle shows that CPS-like continuations are created, but instead of passed in, they are shallowly returned.
List TransformationsKyle introduces the Array.map() method and explains how it can be used to create immutable list transformations. Transforming a list involves performing an operation on every value in that list. The new list of transformed values has a one-to-one “mapping” with the original list.
Filter: ExclusionKyle reviews the Array.filter() as a method 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.
Reduce: CombiningKyle introduces Array.reduce() method as a combiner. 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.
Challenge 7: Culmination ExerciseIn this challenge, students work through a number of the concepts taught throughout this course. Before starting the exercise, Kyle shares a few observations about the process of learning functional programming.
Challenge 7: SolutionKyle begins walking through the solution by creating an addn() function that takes an array of values and adds them together using the add2() function.
Challenge 7: Solution 2Building off the previous solution, Kyle changes the addn() function to now work with an array of functions instead of an array of values creating an appraoch that allows the incorporation of the reduce() method. - Tthere's a horn that starts at 04:53:33:20 and lasts till 04:58:35:13
Challenge 7: Solution 3The last step in the exercise 4 solution is to incorporate the filter() method so only odd or even values can be passed to addn().
FusionKyle introduces the concept of fusion, which deals with combining adjacent operators to reduce the number of times the list is iterated over.
TransducingKyle shows how to create transducers, which are composable and efficient data transformation functions that do not create intermediate collections.
Data Structure Operations
Data Structure Operations IntroductionKyle reviews lists, which are typically visualized as arrays, but can be generalized as any data structure that represents/produces an ordered collection of values. As such, all these "list operations" are actually "data structure operations."
Challenge 8: Culmination Exercise 2In this challenge, students take all the concepts discussed in the course and use them to solve a coding exercise.
Challenge 8: SolutionKyle walks through the solution to Challenge 8 and takes questions from students.
Functional Programing Utility
FPO.jsKyle introduces his FP library, FPO.js, whose methods are all styled to use named-arguments (object parameter destructuring) instead of individual positional arguments.
Lazy ArraysKyle illustrates that "eager" and "lazy" are ways to describe whether an operation will finish right away or progress over time. A "lazy array" is an array where the values will come in over time.
Challenge 9: ObservablesIn this challenge, students program a countdown timer using observables.
Challenge 9: SolutionKyle walks through the solution to Challenge 9 and takes questions from students.