meteor / meteor-feature-requests

A tracker for Meteor issues that are requests for new functionality, not bugs.
Other
89 stars 3 forks source link

Enable F#-Style Pipeline Operator #385

Open vlasky opened 4 years ago

vlasky commented 4 years ago

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:

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

hexsprite commented 4 years ago

Why does this need to be part of Meteor? You can just enable this on a per-project basis using the .babelrc configuration...