Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Feature Request: pipeline function because people want a pipe operator since 2020 #5962

Open
@paulftw

Description

@paulftw

tc39/proposal-pipeline-operator made the hack pipe cool again.
If, when, and in what shape it is going to get through is an open question, butlodash can deliver pretty much the same fun with one simple function.

Consider the above proposal's main usage example:

Object.keys(envars).map(envar=>`${envar}=${envars[envar]}`).join(' ')|> `$ ${%}`|>chalk.dim(%,'node',args.join(' '))|>console.log(%);

Almost same "coding experience" can be achieved utilizing modern JS features (not so modern as of 2025):

// async is omitted for brevity, see belowconstpipeline=(initial, ...lambdas)=>lambdas.reduce((acc,fn)=>fn(acc),initial)pipeline(Object.keys(envars).map(envar=>`${envar}=${envars[envar]}`).join(' '),$=>`$${$}`,$=>chalk.dim($,'node',args.join(' ')),$=>console.log($),)

Withlodash.pipeline one could literally:

  1. copy-paste any snippet fromtc39/proposal-pipeline-operator
  2. replace all occurrences of% with$ or_ (one even has freedom to choose their personal favorite)
  3. replace|> with$ =>
  4. add trailing comas
  5. wrap everything in apipeline(...) call.

It can be done today, without waiting for TC39 decision, browser and tooling support, etc.

Only downside versus the proposal I could think of so far is apparently it cannot supportyield.
I'm not sure if and how well the proposal will implementyield, maybe others can weigh in.

Sample implementation I've offered above doesn't work for async code, async-aware version would look like this:

constpipeline=async(initial, ...lambdas)=>lambdas.reduce(async(acc,fn)=>fn(awaitacc),initial)

Open questions I hope others would weigh in on:

  1. Should it be calledpipeline orpipe or else? (with this approach we get rid of the proposal's% bikeshedding, so let's bikeshed this one instead)
  2. In case of sync codeawait is redundant. Is it that bad for performance? Is it a big enough reason not to go this route?
    • I think not, but if yes, what about having sync and async versions...
  3. Can anything be done aboutyield? I see it so rarely in the wild, not sure when it shines.
  4. Am I missing something obvious?

What do you guys think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp