Introduction
- Brian introduces the course, and explains what the intended audience is.
- Brian explores three small tests to determine if one is writing a function: the object needs to be total, have an input for every output, be deterministic, and have no observable side effects.
- Brian reviews the checklist of what makes a mathematical, pure function, and asks the audience to determine if the examples presented are pure functions or not.
- Brian explains how the mathematics used in functions can be useful when programming. Pure functions are reliable, portable, reusable, testable, and composable.
Currying
Composition
Functors
Either Monad
- Brian explains that the type Either is a functor and a monad, it has both a map, a chain method, and a fold method. The Either type respects function purity and is effectively an if else statement, but inverted.
- Brian explains that fromNullable is useful because it is a definitive null check for every function, and avoids repetition.
- Brian demonstrates through a server example how to use the Either monad to refactor code.
- Brian demonstrates how to flatten the Either monad using both the chain and map methods.
- Brian recommends using the Either type instead of exploring specific syntax that only covers one unique way of using the type.
- Brian goes over examples of using the Either type using the dot syntax, and explains that, when working with Either, it is not possible to flatten an array of another type.
- Brian demonstrates how to use logs to debug the code, and answers questions about the Writer monad, a monad that, along with values, returns an error message.
Task
- Brian explains that the Task monad is the functional equivalent of promise. Similarly to promise, Task takes resolve and reject functions, but in reversed order. A Task monad only starts running once it reaches the fork method, and this way avoids race conditions.
- Brian explains that Node IO, although commonly used, does not bring in any asynchronicity, and demonstrates how to use Task instead which gives a clean control flow.
- Brian goes over different Task monad examples and familiarizes the audience with the Task syntax, and characteristics.
- Brian explores various transformations, such as type transformations, free monads, and monoids with both the either and task monad.
- Brian demonstrates how to fetch weather data from the weather API, and explains the next data parsing steps.
- Brian builds a task monad to fetch data from an API and refactors the code using the Task monad.
- Brian demonstrates how to use the Task monad when creating a weather module, and how to use the monad in different places within the same application.
- Brian uses HTML to show some of the results gathered through the weather API on the screen, live codes a weather data type, and refactors the code into new types, making the application cleaner, and the functions within it more accessible.