Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Latest commit

 

History

History
317 lines (302 loc) · 21.6 KB

additional-feature-ba.md

File metadata and controls

317 lines (302 loc) · 21.6 KB
Name Status Features Purpose
Core Proposal Stage 0 Infix pipelines … |> …
Lexical topic #
Unary function/expression application
Additional Feature BC None Bare constructor calls … |> new … Tacit application of constructors
Additional Feature BA None Bare awaited calls … |> await … Tacit application of async functions
Additional Feature BP None Block pipeline steps … |> {…} Application of statement blocks
Additional Feature PF None Pipeline functions +> Partial function/expression application
Function/expression composition
Method extraction
Additional Feature TS None Pipeline try statements Tacit application to caught errors
Additional Feature NP None N-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 style Valid bare style Invalid 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() 🚫