mostly-adequate-guide
  • README
  • Chapter 01: What Ever Are We Doing?
    • Introductions
    • A Brief Encounter
  • Chapter 02: First Class Functions
    • A Quick Review
    • Why Favor First Class?
  • Chapter 03: Pure Happiness with Pure Functions
    • Oh to Be Pure Again
    • Side Effects May Include...
    • 8th Grade Math
    • The Case for Purity
    • In Summary
  • Chapter 04: Currying
    • Can't Live If Livin' Is without You
    • More Than a Pun / Special Sauce
    • In Summary
    • Exercises
  • Chapter 05: Coding by Composing
    • Functional Husbandry
    • Pointfree
    • Debugging
    • Category Theory
    • In Summary
    • Exercises
  • Chapter 06: Example Application
    • Declarative Coding
    • A Flickr of Functional Programming
    • A Principled Refactor
    • In Summary
  • Chapter 07: Hindley-Milner and Me
    • What's Your Type?
    • Tales from the Cryptic
    • Narrowing the Possibility
    • Free as in Theorem
    • Constraints
    • In Summary
  • Chapter 08: Tupperware
    • The Mighty Container
    • My First Functor
    • Schrödinger's Maybe
    • Use Cases
    • Releasing the Value
    • Pure Error Handling
    • Old McDonald Had Effects...
    • Asynchronous Tasks
    • A Spot of Theory
    • In Summary
    • Exercises
  • Chapter 09: Monadic Onions
    • Pointy Functor Factory
    • Mixing Metaphors
    • My Chain Hits My Chest
    • Power Trip
    • Theory
    • In Summary
    • Exercises
  • Chapter 10: Applicative Functors
    • Applying Applicatives
    • Ships in Bottles
    • Coordination Motivation
    • Bro, Do You Even Lift?
    • Operators
    • Free Can Openers
    • Laws
    • In Summary
    • Exercises
  • Chapter 11: Transform Again, Naturally
    • Curse This Nest
    • A Situational Comedy
    • All Natural
    • Principled Type Conversions
    • Feature Envy
    • Isomorphic JavaScript
    • A Broader Definition
    • One Nesting Solution
    • In Summary
    • Exercises
  • Chapter 12: Traversing the Stone
    • Types n' Types
    • Type Feng Shui
    • Effect Assortment
    • Waltz of the Types
    • No Law and Order
    • In Summary
    • Exercises
  • Chapter 13: Monoids bring it all together
    • Wild combination
    • Abstracting addition
    • All my favourite functors are semigroups.
    • Monoids for nothing
    • Folding down the house
    • Not quite a monoid
    • Grand unifying theory
    • Group theory or Category theory?
    • In summary
    • Exercises
  • Appendix A: Essential Functions Support
    • always
    • compose
    • curry
    • either
    • identity
    • inspect
    • left
    • liftA2
    • liftA3
    • maybe
    • nothing
    • reject
  • Appendix B: Algebraic Structures Support
    • Compose
    • Either
    • Identity
    • IO
    • List
    • Map
    • Maybe
    • Task
  • Appendix C: Pointfree Utilities
    • add
    • append
    • chain
    • concat
    • eq
    • filter
    • flip
    • forEach
    • head
    • intercalate
    • join
    • last
    • map
    • match
    • prop
    • reduce
    • replace
    • reverse
    • safeHead
    • safeLast
    • safeProp
    • sequence
    • sortBy
    • split
    • take
    • toLowerCase
    • toString
    • toUpperCase
    • traverse
    • unsafePerformIO
Powered by GitBook
On this page
  • About this book
  • Read it Online
  • Play Around with Code
  • Download it
  • Do it yourself
  • Table of Contents
  • Plans for the future

Was this helpful?

README

Last updated 7 months ago

Was this helpful?

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 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.

Read it Online

For a best reading experience, .

  • Quick-access side-bar

  • In-browser exercises

  • In-depth examples

Play Around with Code

To make the training efficient and not get too bored while I am telling you another story, make sure to play around with the concepts introduced in this book. Some can be tricky to catch at first and are better understood by getting your hands dirty. All functions and algebraic data-structures presented in the book are gathered in the appendixes. The corresponding code is also available as an npm module:

$ npm i @mostly-adequate/support

Alternatively, exercises of each chapter are runnable and can be completed in your editor! For example, complete the exercise_*.js in exercises/ch04 and then run:

$ npm run ch04

Download it

Do it yourself

⚠️ This project setup is now a bit old and thus, you may run into various issues when building this locally. We recommend to use node v10.22.1 and the latest version of Calibre if possible.

About the nodejs version

  • Install any node version that you need:

nvm install 10.22.1
nvm install 20.2.0
  • Then you will be able to switch between node versions:

nvm use 10.22.1
node -v // will show v10.22.1 
nvm use 20.2.0
node -v // will show v20.2.0

As this project has a .nvmrc file you can call nvm install and nvm use without specifying the node version:

// being anywhere inside this project
nvm install
node -v // will show v10.22.1

Complete sequence of commands

Considering the above about having nvm installed on your system, here is the complete sequence of commands to generate pdf and epub files by yourself:

git clone https://github.com/MostlyAdequate/mostly-adequate-guide.git
cd mostly-adequate-guide/
nvm install
npm install
npm run setup
npm run generate-pdf
npm run generate-epub

Table of Contents

Contributing

Translations

FAQ

Plans for the future

  • Part 1 (chapters 1-7) is a guide to the basics. I'm updating as I find errors since this is the initial draft. Feel free to help!

  • Part 2 (chapters 8-13) address type classes like functors and monads all the way through to traversable. I hope to squeeze in transformers and a pure application.

  • Part 3 (chapters 14+) will start to dance the fine line between practical programming and academic absurdity. We'll look at comonads, f-algebras, free monads, yoneda, and other categorical constructs.


Find pre-generated PDF and EPUB as .

As the recommended node version (v10.22.1) is a bit old now, is more than likely that you do not have it installed on your system. You can have multiple versions of nodejs installed on your system using . Refer to that project to install it and then you will be able to:

Note! To generate the ebook version you will need to install ebook-convert. .

See

See

See

See

This work is licensed under a .

build artifacts of the latest release
nvm
Installation instructions
SUMMARY.md
CONTRIBUTING.md
TRANSLATIONS.md
FAQ.md
read it online via Gitbook
Creative Commons Attribution-ShareAlike 4.0 International License