Awesome Open Source
Awesome Open Source

Functional Programming Resources

An archive of the best resources surrounding the functional programming paradigm.

Object Orientation makes code understandable by encapsulating moving parts. Functional programming makes code understandable by minimizing moving parts. ~ Michael Feathers

Functional programming is making a strong comeback, and with it: a massive wave of internet buzz. Someone needs to sort the good from the bad, and that is what I will attempt to do here.

My focus is on the functional paradigm in the context of Javascript, but discussion and highlight of other Functional languages are welcome for the purpose of evaluation, comparison and education.

Note: This is very much a work in progress! Pull Requests welcome!

Keywords

  • Higher-Order Functions A fancy term for a function that accepts another function as an argument. source
  • Currying Currying is the process of transforming a function that takes multiple arguments into a function that takes just a single argument and returns another function if any arguments are still needed. source
  • Pure Functions A pure function is a function that does not introduce any "side effects" by affecting state anywhere in your application. Pure functions return a value, and that is all they do. This keeps your functions clean, predictable, and highly-testable.
  • Functors A functor is a container that you can map over; apply a function to its contents & return a new container with results. e.g. JS Arrays.
  • Monad In functional programming, a monad is a structure that represents computations defined as sequences of steps: a type with a monad structure defines what it means to chain operations, or nest functions of that type together. This allows the programmer to build pipelines that process data in steps, in which each action is decorated with additional processing rules provided by the monad. source
  • Immutable Immutable values are values that never change once instantiated. All variables (symbols) are immutable in functional languages.
  • Tail Call A tail call happens when a function F makes a function call as its final action. At that point F will do absolutely no more work: it passes the ball to whatever function is being called and vanishes from the game. source

Articles

Videos & Presentations

Video Series: Functional Programming in Javascript

Created by Mattias P Johansson twitter | youtube

Courses (free and paid)

Interactive Online Courses

Benefits of Functional Programming

  • Unit Testing No function can ever cause side-effects, there is no need to care about external state, or calling functions in any particular order, all you need to do is pass arguments to your functions that represent your edge cases, this makes unit testing an absolute dream, and your applications can ship with confidence!
  • Debugging Debugging a functional program is a breeze. If a function doesn't behave appropriately, just take a peek at your stack, and all the functions and variables that lead you to this point are staring right at you. No need to examine any external state, or investigate who/what/where could have interfered, it's all right in front of you.
  • Concurrency The functional programming paradigms offers concurrency as a bonus right out of the box. Nothing in a functional program is ever modified twice by the same thread, let alone by two different threads. There is never any need to use locks, or worry about race conditions. Add as many threads to your app as you want, and your program will keep humming away. Beautiful.
  • Hot Code Deployment Ever wish you could update/patch your live application without having to shut the system down first? With FP, it's not a problem!
  • Machine-Assisted Proofs & Optimizations Because functional languages share a common root in mathematics, tooling for optimizations, testing, evaluation, etc can be built to further demonstrate the validity of your application. See "Machine Assisted Proofs and Optimizations" for more information.
  • Highly-Readable Code FP is an extremely expressive design paradigm, and this expressiveness tends to lend itself to beautifully-crafted programs that are clear and concise.
  • Excellent Code Reuse The FP paradigm supports modular, reusable code straight out of the box. This is because functions compose themselves of existing functions, so you get to decide how these functions are combined to perform your application logic.
  • Highly-Maintainable Code FP programs are incredibly easy to read, due to the declarative (and modular) nature of functional programming. Additionally: Functional programs also tend to be shorter than their imperative counterparts, and a smaller code base is easier to maintain than a large one.
  • Static Types In FP, all 'variables' (immutable symbols) have a type (either declared, or inferred at compile-time). The compiler can then analyse your code and help you avoid a wide range of common problems that plague developers in non statically-typed languages. Note: Javascript is not a statically-typed language, see the "Gotchas" section.

The "Gotchas" of Javascript

Certain aspects of the javascript language make it tricky to harness the full power of a fully-functional language, namely:

  • Javascript is not a statically-typed language. Variables in javascript are dynamically-typed, which means that they can change their type at anytime. This is counter to the functional methodology where all symbols are immutable and have an explicit type.
  • Variables are only immutable in ES6. All ECMAScript specifications lower than 6 ( >= ES5 ) do not support immutable variables. Note that the const keyword is available in ES6, where variables declared like const foo = 123; are immutable, but objects declared with const behave differently (see the next gotcha).
  • In ES6, objects declared with const are mutable. The idea here is that the pointer reference to the object is immutable when your object is declared with const, but the object itself is mutable.

Libraries & Frameworks

  • Ramda A utility library with a focus on flexible functional composition enabled by automatic currying and reversed argument order. Avoids mutating data.
  • functionaljs A functional JavaScript library. It facilitates currying and point-free / tacit programming and this methodology has been adhered to from the ground up.
  • lodash - A utility library delivering consistency, customization, performance, & extras. A better and faster Underscore.js.
  • Mout - Utility library with the biggest difference between other existing solutions is that you can choose to load only the modules/functions that you need, no extra overhead.
  • mori - A library for using ClojureScript's persistent data structures and supporting API from the comfort of vanilla JavaScript.
  • Folktale - A suite of libraries for generic functional programming in JavaScript that allows you to write elegant, modular applications with fewer bugs, and more reuse.
  • immutable - Immutable data collections.
  • underscore-contrib - The brass buckles on Underscore's utility belt.
  • Bacon.js - Functional reactive programming.
  • RxJS - Functional reactive library for transforming, composing, and querying various kinds of data.
  • Lazy.js - Utility library similar to lodash/Underscore but with lazy evaluation, which can translate to superior performance in many cases.

Functional Javascript Books

Functional Programming Books, Papers & Articles

Worthwhile publications on FP in languages other than Javascript.

Resources to be Explored

These are articles and resources that were recommended for one reason or another, but I haven't actually reviewed them to determine their status.

Blogs to Follow

Functional Languages -> Compile to Javascript

Functional UI

Functional Software

Below are examples of Open Source projects using the functional paradigm. Pull requests are welcome for contributions!

FP Lists

Other curated lists of Awesome FP Knowledge



Alternative Project Comparisons
Related Awesome Lists
Top Programming Languages

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Javascript (1,155,559
Programming (18,556
Functional Programming (11,116
Immutable (2,796
Monad (1,939
Functional Language (402
Functional Js (92
Paradigm (37