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

Latest commit

 

History

History
318 lines (303 loc) · 21.6 KB

additional-feature-bc.md

File metadata and controls

318 lines (303 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 BC

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 constructor calls – would make constructor calls terser. It adds a mode to bare style: if a bare-style pipeline step is preceded by a new, then instead of a function call, it is a constructor call. value |> object.Constructor is equivalent to object.Constructor(value). This is backwards compatible with the Core Proposal as well as all other additional features.

Additional Feature BC 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 new, 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 constructor.

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

Valid topic style Valid bare style Invalid pipeline
… |> new C(#) … |> new C … |> new C() 🚫
″″ ″″ … |> (new C) 🚫
″″ ″″ … |> (new C()) 🚫
″″ ″″ … |> new (C) 🚫
″″ ″″ … |> new (C()) 🚫
… |> new o.C(#) … |> new o.C … |> new o.f() 🚫
… |> new o.C(arg, #) const f = $ => new o::C(arg, $); … |> f … |> new o.C(arg) 🚫
… |> new o.make()(#) const C = o.make(); … |> new C … |> new o.make() 🚫
… |> new o[symbol](#) const f = new o[symbol]; … |> f … |> new o[symbol] 🚫
… |> await new o.make()(#) const af = new o.make(); … |> await af … |> new await o.make() 🚫