Transducers: Supercharge your functional JavaScript

This is the first in a series of posts on functional programming in JavaScript. My goal is to make these ideas more accessible to all levels of programmers. Feedback about style, content, etc., would all be greatly appreciated.

One thing that perplexed me early on in my functional programming days was the concept of transducers. I spent a lot of time Googling and found some great articles that went deep into the theory and the underlying mechanics. However, the practical use of them still seemed a bit out of reach. In this post I’ll attempt to explain transducers in a more understandable way and hopefully give you the confidence to use them in your functional JavaScript. While this article attempts to make transducers more accessible, you will need to have some basic knowledge of functional programming in JavaScript. Specifically, you should know about function composition and iterator functions like .map(), .filter(), and most importantly, .reduce(). If you are unfamiliar with these concepts, go get a grasp on them first.

Continue Reading…

The Beauty of Javascript Composition

I’ve been heavily into functional programming with Javascript for quite some time now. Every new line of code I write takes advantage of ES6’s shorthand syntax and functional programming techniques. When updating existing code, I’ll generally use the opportunity to refactor it to a more functional style. But perhaps the greatest benefit is function composition, the process of combining two or more functions to produce a new function.

Function composition lets us combine multiple functions into steps that transform our data as it flows through them. It’s like an assembly line where each step alters the data in some way. Technically you don’t need to use functional code to create a composable function, but when you do, the result is clean, elegant, easily reasoned, and beautiful code.

Continue Reading…