Additional Feature BA

December 8, 2018 · View on GitHub

NameStatusFeaturesPurpose
Core ProposalStage 0Infix pipelines … |> …
Lexical topic #
Unary function/expression application
Additional Feature BCNoneBare constructor calls … |> new …Tacit application of constructors
Additional Feature BANoneBare awaited calls … |> await …Tacit application of async functions
Additional Feature BPNoneBlock pipeline steps … |> {…}Application of statement blocks
Additional Feature PFNonePipeline functions +> Partial function/expression application
Function/expression composition
Method extraction
Additional Feature TSNonePipeline try statementsTacit application to caught errors
Additional Feature NPNoneN-ary pipelines (…, …) |> …
Lexical topics ##, ###, and ...
N-ary function/expression application

Additional Feature BA

ECMAScript No-Stage Proposal. Living Document. J. S. Choi, 2018-12.

This document is not yet intended to be officially proposed to TC39 yet; it merely shows a possible extension of the Core Proposal in the event that the Core Proposal is accepted.

An additional feature – bare awaited calls – would make async function calls terser. It adds another mode to bare style: if a bare-style pipeline step is preceded by a await, then instead of a mere function call, it is an awaited function call. value |> await object.asyncFunction is equivalent to await object.asyncFunction(value). This would be backwards compatible with the Core Proposal as well as all other additional features.

Additional Feature BA is formally specified in in the draft specification.

With smart pipelines Status quo
value
|> # + '!'
|> new User.Message(#)
|> await stream.write
|> console.log;
console.log(
  await stream.write(
    new User.Message(
      value + '!'
    )
  )
);

If a pipeline step starts with await, followed by a mere identifier, optionally with a chain of properties, and with no parentheses or brackets, then that identifier is interpreted to be a bare awaited function call.

That is: if a pipeline is of the form
topic |> await identifier
or topic |> await identifier0.identifier1
or topic |> await identifier0.identifier1.identifier2
or so forth,
then the pipeline is a bare async function call.

Valid topic styleValid bare styleInvalid pipeline
… |> await af(#)… |> await af… |> await af() 🚫
″″″″… |> (await f) 🚫
″″″″… |> (await f()) 🚫
″″″″… |> await (f) 🚫
″″″″… |> await (f()) 🚫
… |> af |> await #″″… |> af |> await 🚫
… |> await o.f(#)… |> await o.f… |> await o.f() 🚫
… |> await o.make()(#)const af = o.make(); … |> await af… |> await o.make() 🚫
… |> await new o.make()(#)const af = new o.make(); … |> await af… |> new await o.make() 🚫

[Unix pipe]: https://en.wikipedia.org/wiki/Pipeline_(Unix [untangled flow]: ./goals.md#untangled-flow [Visual Basic’s select statement]: https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/select-case-statement [WebKit console variables]: https://webkit.org/blog/829/web-inspector-updates/ [WHATWG Fetch + CP]: ./core-real-examples.md#whatwg-fetch-standard [WHATWG Fetch Standard]: https://fetch.spec.whatwg.org/ [WHATWG Streams + CP + BP + PF + NP]: ./additional-feature-np.md#whatwg-streams-standard-core-proposal--additional-features-bppfmt [WHATWG Streams + CP + BP + PF]: ./additional-feature-pf.md#whatwg-streams-standard-core-proposal--additional-feature-bppf [WHATWG Streams Standard]: https://stream.spec.whatwg.org/ [WHATWG-stream piping]: https://streams.spec.whatwg.org/#pipe-chains [Wikipedia: term rewriting]: https://en.wikipedia.org/wiki/Term_rewriting [zero runtime cost]: ./goals.md#zero-runtime-cost