Earlier this week, a TC39 proposal for a pipeline operator moved to stage-1. If the proposal is eventually accepted and included in the ECMAScript standard — it has a long way to go — it will offer a new syntax for lettable operators.
What is proposed?
The proposed pipeline operator is
|>. It’s a binary operator; the operand to its left is a value and the operand to its right is a function. The pipeline operator calls the function, passing the value as an argument, and returns the function’s result.
64 |> Math.sqrt is equivalent to
Using the pipeline operator, multiple functions can be pipelined, like this:
How would it be used with lettable operators?
The lettable operators introduced in the RxJS 5.5.0 beta are higher-order functions. They return functions that receive and return observables. As such, they can be used with the proposed pipeline operator, like this:
Whether or not the pipeline proposal will navigate its way through the TC39 process to be included in the ECMAScript standard remains to be seen.
However, if you like to live at the bleeding edge, there is a Babel plugin for the proposal:
babel-plugin-transform-pipeline. It does have some issues with recent Babel packages, but with the proposal at stage-1, it should not be long before an up-to-date plugin is included in Babel’s stage-1 preset.
This post is also published on my personal blog: ncjamieson.com.