The pipeline operator is essentially a useful syntactic sugar on a function call with a single argument. In other words,
sqrt(64)
is equivalent to64 |> sqrt
.This allows for greater readability when chaining several functions together.
With the Pipeline Operator, one could rewrite this …
let result = exclaim(capitalize(doubleSay("hello")));
… to this (think Unix pipes!):
let result = "hello"
|> doubleSay
|> capitalize
|> exclaim;
The proposal also caters for functions with multiple arguments with arrow functions or partial application.
The proposal is currently Stage 1
💁♂️ Stage-1?
The Technical Committee which is concerned with the standardization of ECMAScript (i.e. TC39) has a 5 stage process in place, ranging from stage-0 to stage-4, by which it develops a new language feature.
Stage-1 is the Proposal stage. It signals that the committee is showing interest in the proposal and that it is seeking further investigation on how to tackle it. At this stage the proposal is subject to heavy changes. It is only when a proposal reaches Stage 4 that it is ready to become part of the ECMAScript Specification.
ESNext Proposal: The Pipeline Operator →
Related: Whilst this proposed operator only gets me lightly excited, one that does get me very excited is The Null Propagation Operator. You should definitely check it out.
Leave a comment