tc39 / proposal-pipeline-operator

A proposal for adding a useful pipe operator to JavaScript.
http://tc39.github.io/proposal-pipeline-operator/
BSD 3-Clause "New" or "Revised" License
7.43k stars 109 forks source link

Function composition models pipelines #304

Open mlanza opened 1 month ago

mlanza commented 1 month ago

Let's start with the standard F# pipeline as implemented by Babel:

const a = x 
  |> f(?, 1)
  |> g
  |> h

This gives you a where x, some value, is passed down the pipeline. Function composition syntax can be similarly achieved.

const y = // x is omitted 
  |> f(?, 1)
  |> g
  |> h

//this syntax is equivalent to:

const y = comp(h, g, f(?, 1));  

/* so that... */

const a = y(x);

Given a basic pipeline syntax, one drops the initial input argument and, conveniently, ends up with a composed function. This makes sense given that function composition and pipelines are so closely related.

There should be little reason, once the pipeline syntax is settled, that function composition syntax couldn't tag along.

snatvb commented 1 month ago

question symbol aready assiciated with optional, better than sharp - # I don't know, maybe is percent(%) could be, but # looks better and don't uses as math opeator, that can confuse

const y = // x is omitted 
  |> f(#, 1)
  |> g
  |> h