Member-only story
Functional Programming and the Pipe Function in JavaScript
What is pipe and how can we use it?
When you want to do something but it’s quite complex to be in one function, how do you solve this problem? What if you want to separate the function into many pieces but you want to do something more elegantly?
There’s an interesting proposal on TC39 GitHub — proposal-pipeline-operator at stage 1. Although it’s still unsettled as it’s mentioning, the idea of the proposal is quite fun to take a look at.
In this post, I will talk about pipe or pipeline which is important when it comes to functional programming and how to write them.
Before Reading
This post is under the premise that you are aware of JavaScript basics and some of the built-in methods in the Array.prototype
.
If you aren’t familiar with those, I recommend you read the documentation about them. And, the way I make pipeline functions might be different from other pipelines in the JavaScript world. But the core concept wouldn’t be so different.
Plus, I will explain pipe
and how to create it step-by-step for people who have no idea about it.