# Hardcore Functional Architecture Patterns in JavaScript

Table of Contents

## Introduction

### Introduction

Brian introduces the course by explaining that architecture is about grouping things, and gives a refresher on the main functional programming properties.### Naming & Grouping

Brian introduces the identity functor, and explains that it takes a value and returns a value. The identity functor is founded on category theory, which states that functional programming necessitates both composition and identity.### Composition Architecture

Brian compares working with one big function that does all the work with little functions that represent small functionalities from a given application, and says that this course will focus on composition involving multiple small functions.### Normalize Effect Types

Brian explains that normalizing the effect types within the app is a good guiding principle to allow every element within the app to compose, and says that different ways to solve this issue will be reviewed in the next sections.

## Semigroups & Monoids

### What is a Semigroup

Brian explains that a semigroup is a structure that contains an associative operation, and that is closed. Explanation is given for why a closed and associative.### Creating Semigroup Data Types

Brian explains how to lift an operation through a type to be able to program an interface.### Defining Empty Identity

Brian explains that monoids are semigroups with an identity, and live codes examples of monoids.### foldMap

Brian explains that foldMap takes elements, maps them into a certain type, and then folds them.### Semigroup vs Monoid

Brian explains the main differences between a monoid and a semigroup. A semigroup can have an empty identity.### Identity Functor

Brian explains that functors are monoids, and demonstrates the advantages of programming to an interface. Programming to an interface means referring to a more abstract level than a class.### Concat Method

Brian demonstrates how to concat different functors together, and how to use the concat method to join different monoids.### Monoid Exercises

The students are instructed to code different monoid exercises.### Monoid Solutions

Brian live codes the solutions to the monoid exercises.### Monoid Use Cases

Brian shares two use cases for monoids to demonstrates how monoids can be used in everyday code and make code cleaner.### Homomorphisms & Monads

Brian gives an example of a homomorphism. A homomorphism takes two elements and combines them then goes through a type transformation. At a high level, when combining a monoid operation and flattening two types, these types become monads.### Creating a Validation Library

Brian demonstrates how to architect an app around validation, and builds a validation library that combines different kinds of validations, and provides errors or a final object.### Creating Success & Fail Monoids

Brian demonstrates how to create success and failure types, and adds a concat method, therefore building two monoids.### Creating the Validation Monoid

Brian continues to develop the validation library, and demonstrates how to create a validation monoid.

## Function Modeling

### Function Modeling

Brian explains that, instead of modeling data, it is possible to model a function. Functional modelling allows to use different methods.### The Reader Monad

Brian demonstrates how to use the Reader monad to add dependency connections and thread invisible environments through an entire program.### The Endo Functor

Brian explain that the endofunctor is called endo because it only works with the same kind of types.### contramap

Brian explains that contramap maps over inputs, combines two reducers that were previously contermapped demonstrating that contermap hits arguments before it comes in.### Function Modeling Practices

Brian live codes function modeling and demonstrates how to use Endofunction, predicate, and how to use the contramap or contravariant functor. An endofunction is a function that has an equal domain and codomain.### Function Modeling Equivalences

Brian demonstrates how to combine reducer functions, and transform them into an Endo type, and explains that the two are equivalent.### Composing Functors

Brian explores different types of functors using the map, extract and fork methods, and explains that functors have different identities, can be composed together, and have a category within which they act like functions.### Monad Transformers

Brian explores the use of monad transformers with the Task transformer which contains a lift method that will avoid duplicating an inner type. A transformer is a monad that merges two monads together. Transformers are needed because unlike functors, monads do not compose.### Reconstructing with Monad Transformers

Brian introduces monad transformer based libraries, and explains that each transformer is useful for a specific task, and reconstructing code with monad transformers requires understanding which transformer to use at the right place.### Monad Transformers Practices

Brian covers monad transformer practices, and demonstrates how to use the lift method.### Defining the Free Monad

Brian explains that the free monad is a way to treat functions like datatypes, and gives an example of a free monad that takes a url as an argument, returns a datatype, and the content of the argument, in this example, the url.### Lenses

Brian explains that lenses are built on functors and, compose backwards going left to right, adds that it is possible to write an entire application with lenses, and demonstrates how to treat properties as functors.

## Monadic Web Apps

### Building a CLI App

Brian explores how to build a CLI blog for creating and viewing blogposts by focusing on the architectural decisions to build the app in a functional way.### Refactoring Recursive Tasks

Brian continues building the CLI blog and uses different forms of function modeling to refactor code, such as the fix type.### Free Monads

Brian continues to refactor the CLI blog app using Free monads to test the different app tasks.### Interpreters

Brian adds interpreters to the different free monads. Interpreters allow developers to log information about how the Free monad runs.### Creating an Alternative Redux

Brian explores a new application and starts building an alternative Redux that is contained in the event loop. Redux is a bare-bones approach to functional UI. The alternative takes advantage of monads, function modeling, monoids, and lenses.### Using the ask Method & Lenses

Brian continues to build the application started in the previous section so that state is merged automatically when the ask method runs, uses lenses to alter state in an elegant and immutable way, and builds reducers that compose and are unary functions.