DEV Community

Cover image for The wavy dot operator
Alfredo Salzillo
Alfredo Salzillo

Posted on

3 2

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?

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay