DEV Community 👩‍💻👨‍💻

Cover image for The wavy dot operator
Alfredo Salzillo
Alfredo Salzillo

Posted on

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?

Top comments (0)

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.