⪼ Made with 💜 by Polyglot.
The Pipe Operator (
|>
) is a feature that aims to introduce a more concise and readable way to chain function calls in JavaScript. It takes the value on its left-hand side and passes it as the first argument to the function on its right-hand side, creating a "pipeline" of operations.
- A Look at the JavaScript Pipeline Operator Proposal
- Introducing JavaScript's Pipe Operator
- 7.5.0 Released: dynamic import and F# pipelines
- What's Happening With the Pipeline (|>) Proposal?
- ES pipe operator (2021)
- tc39/proposal-pipeline-operator
- @babel/plugin-syntax-pipeline-operator
- @babel/plugin-proposal-pipeline-operator
The operator is chaining multiple function calls together, creating a "pipeline" of operations. This can be used in endless real life scenarios especially in algorithmic workflows and data processing.
const numbers = [1, 2, 3, 4, 5];
const doubledAndFiltered = numbers
|> ((arr) => arr.map((n) => n * 2))
|> ((arr) => arr.filter((n) => n > 6));
console.log(doubledAndFiltered);
As of
January 10, 2024
, the pipeline operator is not yet a part of the official JavaScript language. But for now you can use a transpiler like Babel so the current JavaScript engines can understand this experimental feature.
npm install --save-dev @babel/plugin-proposal-pipeline-operator
babel.config.json
{
"plugins": ["@babel/plugin-proposal-pipeline-operator"]
}