Table of Contents

Introduction 1.1 Chapter 1: What ever are we doing? 1.2 Introductions 1.2.1 A brief encounter 1.2.2 Chapter 2: First Class Functions 1.3 A quick review 1.3.1 Why favor first class? 1.3.2 Chapter 3: Pure Happiness with Pure Functions 1.4 Oh to be pure again 1.4.1 Side effects may include… 1.4.2 8th grade math 1.4.3 The case for purity 1.4.4 In Summary 1.4.5 Chapter 4: 1.5 Can’t live if livin’ is without you 1.5.1 More than a pun / Special sauce 1.5.2 In Summary 1.5.3 Chapter 5: Coding by Composing 1.6 Functional Husbandry 1.6.1 Pointfree 1.6.2 Debugging 1.6.3 Category Theory 1.6.4 In Summary 1.6.5 Chapter 6: Example Application 1.7 Declarative Coding 1.7.1 A flickr of 1.7.2 A Principled Refactor 1.7.3 In Summary 1.7.4 Chapter 7: Hindley-Milner and Me 1.8 What’s your type? 1.8.1 Tales from the cryptic 1.8.2 Narrowing the possibility 1.8.3 Free as in theorem 1.8.4 In Summary 1.8.5 Chapter 8: Tupperware 1.9 The Mighty Container 1.9.1 My First Functor 1.9.2 Schrödinger’s Maybe 1.9.3 Pure Error Handling 1.9.4 Old McDonald had Effects… 1.9.5 Asynchronous Tasks 1.9.6 A Spot of Theory 1.9.7 In Summary 1.9.8 Chapter 9: Monadic Onions 1.10 Pointy Functor Factory 1.10.1 Mixing Metaphors 1.10.2 My chain hits my chest 1.10.3 Theory 1.10.4 In Summary 1.10.5 Chapter 10: Applicative Functors 1.11 Applying Applicatives 1.11.1 Ships in bottles 1.11.2 Coordination Motivation 1.11.3 Bro, do you even lift? 1.11.4 Free can openers 1.11.5 Laws 1.11.6 In Summary 1.11.7

About this book

This is a book on the functional paradigm in general. We’ll use the world’s most popular functional programming language: JavaScript. Some may feel this is a poor choice as it’s against the grain of the current culture which, at the moment, feels predominately imperative. However, I believe it is the best way to learn FP for several reasons:

You likely use it every day at work.

This makes it possible to practice and apply your acquired knowledge each day on real world programs rather than pet projects on nights and weekends in an esoteric FP language.

We don’t have to learn everything up front to start writing programs.

In a pure functional language, you cannot log a variable or read a DOM node without using monads. Here we can cheat a little as we learn to purify our codebase. It’s also easier to get started in this language since it’s mixed paradigm and you can fall back on your current practices while there are gaps in your knowledge.

The language is fully capable of writing top notch functional code.

We have all the features we need to mimic a language like Scala or Haskell with the help of a tiny library or two. Object-oriented programming currently dominates the industry, but it’s clearly awkward in JavaScript. It’s akin to camping off of a highway or tap dancing in galoshes. We have to bind all over the place lest this change out from under us, we don’t have classes (yet), we have various work arounds for the quirky behavior when the new keyword is forgotten, private members are only available via closures. To a lot of us, FP feels more natural anyways.

That said, typed functional languages will, without a doubt, be the best place to code in the style presented by this book. JavaScript will be our means of learning a paradigm, where you apply it is up to you. Luckily, the interfaces are mathematical and, as such, ubiquitous. You’ll find yourself at home with swiftz, scalaz, haskell, purescript, and other mathematically inclined environments.

Gitbook (for a better reading experience)

Read it online Download EPUB Download Mobi (Kindle)

Do it yourself

git clone https://github.com/DrBoolean/mostly-adequate-guide.git

cd mostly-adequate-guide/ npm install gitbook-cli -g gitbook init

brew update brew install Caskroom/cask/calibre

gitbook mobi . ./functional.mobi Table of Contents