The wavy dot operator

alfredosalzillo

Alfredo Salzillo

Posted on May 27, 2021

The wavy dot operator

What do you think about the wavy-dot operator proposal?

GitHub logo tc39 / proposal-wavy-dot

TC39 Wavy Dot ("~.") Proposal

proposal-wavy-dot

Pleasant Notation for promise pipelining.

  • Mark S. Miller @erights, Agoric
  • Michael Fig @michaelfig, Agoric
  • Chip Morningstar @FUDCo, Evernote

Status

Presented to TC39 (Javascript standards committee), achieving stage 1.

Presentation to TC39

Slides

Summary

This is a follow on proposal to proposal-eventual-send, providing syntactic sugar for the APIs of that proposal.

The 2011 ECMAScript strawman concurrency proposal also described a simple desugaring of an infix bang (!) operator to support promise pipelining. To avoid conflict with TypeScript, this proposal instead introduces the wavy dot (~.) syntax.

Wavy Dot

Like the (?.) of the optional chaining proposal, wavy dot (~.) is a proposed infix operator with the same precedence as dot (.). Both can be understood as adjective dot, i.e., an operation that is dot-like, but differs according to the adjective. Once the optional chaining proposal is accepted, we will add…

To sum up the wavy-dot is a new operator ~. to use on PromiseLike object to wave the Promise to the properties of the value resolved by the Promise.
It always return a Promise how will resolve (or reject) with the result of the operation after the dot.

The available operation are

  • property access, using both [] and property name
  • method/function call

For example:


const asyncArray = new Promise((resolve) => resolve([1, 2, 3, 4]))

// Without the wavy-dot operator
console.log((await asyncArray)[0])  // => log: 1
console.log((await asyncArray).length)  // => log: 3
console.log((await asyncArray).join('-'))  // => log: 1-2-3

// With the wavy-dot operator
console.log(await asyncArray~.[0])  // => log: 1
console.log(await asyncArray~.length)  // => log: 3
console.log(await asyncArray~.join~.('-'))  // => log: 1-2-3
Enter fullscreen mode Exit fullscreen mode

Do you think it's useful?

💖 💪 🙅 🚩
alfredosalzillo
Alfredo Salzillo

Posted on May 27, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

The wavy dot operator
javascript The wavy dot operator

May 27, 2021