meteor-feature-requests
meteor-feature-requests copied to clipboard
Enable F#-Style Pipeline Operator
I think many developers would appreciate having the pipeline operator to make code neater, more concise and easier to debug. It is currently an ECMA TC39 Stage 1 proposal.
For those who are unfamiliar with the pipeline operator |>, here is an example. Given the following functions:
const doubleSay = str => str + ", " + str;
const capitalize = str => str[0].toUpperCase() + str.substring(1);
const exclaim = str => str + '!';
The following invocations are equivalent:
//With official Javascript syntax
const result = exclaim(capitalize(doubleSay("hello")));
result //=> "Hello, hello!"
//With pipeline operator
const result = "hello"
|> doubleSay
|> capitalize
|> exclaim;
result //=> "Hello, hello!"
There are currently three variants of the pipeline operator that can be enabled:
- "minimal" – Minimal Pipeline
- "smart" - Smart Pipeline
- "fsharp" - F#-Style Pipeline
The minimal variant would be a poor choice because it does not support the await keyword for asynchronous code.
I consider the fsharp variant to be preferable to the smart variant because of its clearer syntax. Having read some community discussion, other people seem to be leaning towards it.
See these links:
https://babeljs.io/docs/en/babel-plugin-proposal-pipeline-operator https://github.com/valtech-nyc/proposal-fsharp-pipelines
Why does this need to be part of Meteor? You can just enable this on a per-project basis using the .babelrc configuration...