proposals icon indicating copy to clipboard operation
proposals copied to clipboard

Pipeline Operator (Stage 1)

Open hzoo opened this issue 8 years ago • 26 comments
trafficstars

Champion: @littledan Spec Repo: https://github.com/tc39/proposal-pipeline-operator First presented at Sept 2017 meeting: https://github.com/tc39/agendas/blob/master/2017/09.md Slides: https://docs.google.com/presentation/d/1qiWFzi5dkjuUVGcFXwypuQbEbZk-BV7unX0bYurcQsA/edit#slide=id.p Related proposal: Partial Application https://github.com/rbuckton/proposal-partial-application by @rbuckton Related proposal: Function Bind Operator https://github.com/tc39/proposal-bind-operator

Basic Example

Input

let result = "hello"
  |> doubleSay
  |> capitalize
  |> exclaim;
result //=> "Hello, hello!"

Output

let result = exclaim(capitalize(doubleSay("hello")));
result //=> "Hello, hello!"

Initial Implementation (would need updating to v7)

  • Initial Spec PR by @littledan https://github.com/tc39/proposal-pipeline-operator/pull/51

Old/Alternative Implementations

  • Old PR to Babel: https://github.com/babel/babel/pull/3159
  • https://github.com/SuperPaintman/babel-plugin-transform-pipeline
  • << and >>: https://github.com/michaelmitchell/babel-plugin-pipe-composition

cc @gilbert, @SuperPaintman

Implementation

  • [x] Parser PR: https://github.com/babel/babylon/pull/742
  • [x] Transform PR: https://github.com/babel/babel/pull/6335
  • Feedback around relating Pipeline Operator, Function Bind, Partial Application

hzoo avatar Sep 26 '17 15:09 hzoo

There is also another Babylon implementation (https://github.com/airdwing/babylon), which could be already mergeable because the fork was updated one month ago.

nicolo-ribaudo avatar Sep 26 '17 17:09 nicolo-ribaudo

didn't know it was that simple ha - needs hasPlugin, tests, readme, etc though

hzoo avatar Sep 26 '17 17:09 hzoo

Oh right 😅

nicolo-ribaudo avatar Sep 26 '17 17:09 nicolo-ribaudo

Merged the parser PR

hzoo avatar Sep 29 '17 03:09 hzoo

Transform PR: https://github.com/babel/babel/pull/6335, test at https://babeljs.io/repl/build/5099/

hzoo avatar Sep 30 '17 13:09 hzoo

Linking to Dan's syntax concern (not specced) https://github.com/tc39/proposal-pipeline-operator/issues/60

hzoo avatar Sep 30 '17 17:09 hzoo

Some syntax used in the spec repo examples that doesn't parse currently: are these supposed to be?

class Comment extends Model |> Editable |> Sharable {}

hzoo avatar Oct 02 '17 18:10 hzoo

I would expect that to parse as long as Model |> Editable |> Sharable parses, since the RHS of extends is an expression.

ljharb avatar Oct 02 '17 18:10 ljharb

@hzoo You are right, the explained does not match the spec. Sorry for this state of things. I hope to address it soon.

littledan avatar Oct 11 '17 23:10 littledan

Address in the sense of adding more parens in the explainer; I don't have a clear idea of alternative syntax.

littledan avatar Oct 11 '17 23:10 littledan

@js-choi @mAAdhaTTah Could you summarize the current plans here for future reference?

littledan avatar Mar 13 '18 21:03 littledan

@littledan I’ll write one.

Edit: Dang, beaten to it.

js-choi avatar Mar 13 '18 21:03 js-choi

@littledan We're working in parallel on a configuration option for two proposals: F# Pipelines & Smart Pipelines. @js-choi is currently working on the babylon changes required to parse the Smart Pipelines, behind a smartPipelines plugin / flag. Once his is finished, I'm going to follow up with changes of my own behind a fsharpPipelines flag. All of that will be captured in https://github.com/babel/babel/pull/7458

As part of this work, I'll be submitting a PR to the pipeline proposal itself to update the spec to remove any current handling of await, and update the parser to match the current spec, with await being an early error and fixing the current handling of unparen'd arrows. Depending on where we land in https://github.com/tc39/proposal-pipeline-operator/issues/104, F# will either match this behavior or implement the new behavior.

Once the parser changes are complete, we'll then be updating the babel pipeline plugin with a configuration options for these proposals. I don't think we've specified what that flag is just yet, but the intention is to have three "modes": spec, fsharp, & smart, with spec matching whatever's accepted in the current spec.

I'll also eventually be writing up a spec & explainer for F# pipelines. The current spec & explainer for smart pipelines is here: https://github.com/js-choi/proposal-smart-pipelines

mAAdhaTTah avatar Mar 13 '18 21:03 mAAdhaTTah

Is this available to test on the REPL ? I can't get it to work

danielo515 avatar Jun 04 '18 15:06 danielo515

@danielo515 The minimal proposal is in babel right now, but the rest of what I explained is still in progress. Past 2 months have been busy for both JS Choi & me, so we haven't made as much progress as we'd like.

Also, the plan has changed from what was described above; we're going to add all those flags in a fork of babylon (now @babel/parser) and only merge back the version that advances to Stage 2. During that time, the various flags / configurations won't be in babel proper.

mAAdhaTTah avatar Jun 04 '18 15:06 mAAdhaTTah

I think that we could merge them even before stage 2, since now Babylon supports plugin options

nicolo-ribaudo avatar Jun 04 '18 15:06 nicolo-ribaudo

Couple updates I want to drop in here:

  1. Initially, we were going to make the changes in a babylon fork, but as @nicolo-ribaudo helpfully points out, we have options in the parser now, so we can use a single flag for the pipeline operator with options, which will be cleaner than multiple flags.
  2. Suggested by @ljharb, the default for the pipeline operator will be "Throw an error unless you specified which proposal you want," which enables us to go from "no defaults allowed" -> "default is accepted spec" whenever pipeline settles on a particular proposal.

I'll be working on point 2 ASAP, as that needs to land before babel 7 leaves beta.

mAAdhaTTah avatar Jun 04 '18 22:06 mAAdhaTTah

I was curious what was up with the pipeline operator in babel? Every plugin I've tried hasn't worked, and even in the repl with the specified package it won't compile.

I'm excited by this proposal and I recently wrote an article about the pipeline operator (Medium: JS Pipeline Operator Article) and created my own pipeline operator playground: (CodePen: PipeLine Operator Playground).

I was hoping that by now babel would have an official working plugin available for it, but nothing seems to be checking out.

zfrisch avatar Dec 19 '18 21:12 zfrisch

@zfrisch There's a Project on babel with the current status: https://github.com/babel/babel/projects/9 - we have several proposals we're trying to land, so a lot going on before we're done.

mAAdhaTTah avatar Dec 19 '18 22:12 mAAdhaTTah

See also @mAAdhaTTah’s article “What’s Happening with the Pipeline Proposal?”. We’re working on implementing a bunch of preliminary proposals, each with their own trade-offs, so that TC39 and others can try them out, hands on.

js-choi avatar Dec 19 '18 23:12 js-choi

What is the current stage of this proposal?

CC https://github.com/facebook/flow/issues/5443

gajus avatar Jul 06 '19 19:07 gajus

Stage 1, last presented in March 2018

chicoxyzzy avatar Jul 06 '19 19:07 chicoxyzzy

Is this minimal or F#?

goodmind avatar Jul 07 '19 05:07 goodmind

@goodmind none has been selected. It's not until stage 2 that the shape of the solution is mostly settled.

ljharb avatar Jul 07 '19 05:07 ljharb

@ljharb When will be the "stage 2"?

jazithedev avatar Nov 11 '20 15:11 jazithedev

@ktrzos no idea - the champions of the proposal would have to decide its ready, and add it to a meeting agenda in advance of the deadline for doing so, and then the committee would have to agree. The next such opportunity is at the end of January, but it remains up to the proposal champions to decide when that next step is warranted.

ljharb avatar Nov 11 '20 16:11 ljharb