A FUNctional JavaScript Makeover

Mike Schutte
2 min readSep 5, 2018

--

I recently wrote a three-part series (links below, but humor me on a reflective build-up 😊) on refactoring an imperative for loop to pure function composition in JavaScript. After working on a React-Redux application for about six months, my curiosity about why these functional libraries were so hot was too much to ignore, so I set off to understand the way of the lambda. I wrote this series inspired because I found a lot of dense and intimidating resources on FP, and I wanted to help make the paradigm (hopefully) more accessible. You do not have to be a “math person” or a coding-since-I-was-teething kind of person to get some tremendous benefits from functional programming in JavaScript.

Functional programming seems to have a steeper learning curve than more traditional imperative or object-oriented approaches. Explicit instructions and objects cater well to our human imaginations, while things like pointfree style and curried functions can make your JavaScript look totally foreign. I decided to work through these conceptual obstacles solely based on the faith that if React and Redux were solving fundamental web app problems using this paradigm, there must be huge dividends in store for hanging with these sometimes inscrutable syntax patterns and ideas. I encourage you to approach the steep learning curve of functional programming with a similar faith. It might seem over the top or too abstract at first, but the payoffs lie in how flexible and adaptable your code and problem-solving strategies become once you adopt a functional way of thinking.

The first installment covers the foundational concepts for writing functional JavaScript (sans algebraic datatypes). With concepts defined, parts two and three apply them to refactor a common filtering task that probably every JS developer will run into at some point in their career. Follow the links below to see a step-by-step guide on using techniques such as currying and automated function composition

You can find all three parts on the Haught Codeworks blog, along with this video playlist of me working through the refactor in real time on my YouTube channel. The code for said playlist is on Github.

I’d love to hear about why you’re interested in functional programming, what your experience with it thus far has been like, &c. Please leave comments to share and celebrate the process of learning.

--

--

Mike Schutte

Licensed Driver 🚗 TSA Pre ® AeroPress Barista ☕️ Conversational in Emoji 🤟 Anti-mouse (💻✚🏠) Pro-listening 👂he/him 👨‍💻 @TEDTalks