Exploring functional JavaScript

I started exploring functional programming (FP) concepts over a year ago. I have already shared my initial learning materials in one of the previous posts. It was only the beginning of my journey and today I would like to give you a much more detailed update on that topic. I picked the most interesting resources I discovered in the recent months. They helped me understand how functional programming can improve the developer’s experience when you work with JavaScript.

Learning the basics

If you would define yourself as a beginner you might truly enjoy Anjana Vakil‘s talk about how she started her adventure with FP in JavaScript. It’s even more interesting to hear her story knowing that she didn’t have any prior experience with the functional paradigm and a weak background in JavaScript only 6 months before giving this presentation.

Next, I would like to echo a recommendation from my former team mate Radford Smith. This is what he had to say about the Functional JavaScript book:

It’s relatively short (200 pages) but has a lot of useful information.

Indeed this publication seems like a very good introduction, because Michael Fogus presents how to apply functional style concepts with Underscore.js, a JavaScript library that facilitates some of the basic FP techniques like higher-order functions, functional composition, currying, partial application, recursion, purity or immutability.

There is also another resource which seems to be worth mentioning here. Kyle Simpson is about to wrap up his work on the Functional-Light JavaScript book, which aims to explain the core principles of functional programming without using all the mathematical notation. The content of this publication explains in details what Kyle teaches during his training workshops. You can also check this great write up of the Functional-Light JavaScript class written by Beth Allchurch. It should give you a very good idea about what topics are going to be covered in the book.

Going deeper

Once you start searching for more in depth FP learning resources for JavaScript, you quickly discover that this field is dominated by one person – Brian Lonsdorf. He was an object-oriented fanatic for about 5 years, then grew to strongly prefer the functional paradigm. He created the Mostly adequate guide to Functional Programming book to get more folks using functional code in JavaScript. It’s still unfinished work, but there is a community effort to keep the book going and port it to ES6.

Brian also gave a very interesting talk at the Fluent Conference. He blasted through slides presenting functional patterns for the non-mathematician. If you decide to watch it you will be able to discover the gist of the aforementioned book.

Another resource that might catch your attention is Classroom Coding with Professor Frisby. This is a short video series that shows how to build a working application with React and functional techniques in JavaScript. Code is available here:

There are also training videos from the 6 hours long Hardcore Functional Programming in JavaScript live workshop captured by Frontend Masters platform. Joe Nelson and Brian Lonsdorf demonstrate how to build an example JavaScript web app using abstract interfaces like Monads, Functors, Monoids and Applicatives.

Practical appliance

JavaScript was originally designed as an in-browser language to add simple effects to elements on a web page. For years, imperative code was written to be executed from top to bottom. At some point, developers started to take advantage of JavaScript’s nature and features build around objects. Object-oriented programming became the most popular style enthusiastically promoted by library or framework creators. However, there are already a few notable libraries that benefit broadly from using functional paradigms.

I already mentioned Underscore.js, which is actually the first library that tried to promote functional concepts to the wider audience. Brian Lonsdorf in one of his talks explains how it could be done even better.

These days Lodash, which fully implements the Underscore’s API, got much more popular and it is used more willingly in commercial applications. It has a special lodash/fp build which fixes the issues discussed in the above-mentioned presentation. It was achieved by using auto-curried, data last functions with fixed number of params. There is also the other well known alternative called Ramda, which seems to be very popular amongst functional programming enthusiasts.

Facebook is one of the leading companies willing to apply FP paradigms into their products. They started with React and this one simple rule:

All React components must act like pure functions with respect to their props.

Next, they introduced stateless functional components which are defined as a pure JavaScript function. I’d also like to point out that Facebook has hired Dan Abramov and Andrew Clark. Those two guys are creators of Redux, which has evolved the ideas of Flux. It was also inspired by Elm, a functional programming language which compiles to JavaScript. It might mean that the functional style can further extend its presence in the React community.

Finally, I want to recommend a very interesting talk recorded at React Europe conference. Previously mentioned Andrew Clark promotes the idea of building React components as a composition of higher order functions using examples from Recompose utility belt.

Going beyond JavaScript

If you are still reading, it means you really want to master this topic.

When you build real world applications, you are not always on the happy path. Scott Wlaschin in his talk demonstrates a common approach to this challenge within a functional paradigm using a Railway Oriented Programming analogy and F# examples.

You can also find out more about functional programming fundamentals learning Haskell. This is pure functional language so it is entirely appropriate for learning the essential ingredients. As a next step I’m planning to take the online C9 Lectures held by Dr. Erik Meijer who is considered as functional language purist and high priest of the lambda calculus.

Are you still looking for more? Go and check Awesome FP JS – a curated list of functional programming code and learning resources for JavaScript. Enjoy!


This article was reviewed by Fabiana Simões.

Published by

Grzegorz Ziółkowski

Husband, web enthusiast, programmer and basketball fan living in Oleśnica, Poland. JavaScript Wrangler at Automattic.

One thought on “Exploring functional JavaScript”

  1. Nice list. One of the most difficult things about learning functional programming is understanding how to think functionally and apply the concepts to real-world codebases. For that topic I recommend Structure and Interpretation of Computer Programs (also available for free online).

    Don’t get me wrong, it’s a long book and a challenging read. That said, if you’re willing to put in the time and effort, it’s the best book I know to build a deep understanding of functional programming. Many people find it difficult to reconcile object-oriented thinking and functional thinking — this book will remedy that problem. It also provides a framework for writing code that you can build upon and take with you in any programming language, not just Haskell.

    Liked by 1 person

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s