Functional composition is an extremely useful tool when coding in JavaScript. It has a bit of a learning curve but can remove lots of lines of duplicate code while preserving a declarative flow. However, it doesn’t always play nicely with voids, i.e. functions with no explicit returns.

Say we have a function that parses some user data:

const users = [
{ first: 'Syl', age: 21 },
{ first: 'Bill', age: 47 },
{ first: 'Hank', age: 55 },
const getTargetUsers = pipe(
filter(({ age }) => age > 30),
getTargetUsers(users); // ['Bill', 'Hank']);

Easy enough! But…

Aaron Dilley

Front End Developer and Crossword Enthusiast

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store