What do you think about the wavy-dot operator proposal?
Pleasant Notation for promise pipelining.
- Mark S. Miller @erights, Agoric
- Michael Fig @michaelfig, Agoric
- Chip Morningstar @FUDCo, Evernote
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.
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
const asyncArray = new Promise((resolve) => resolve([1, 2, 3, 4])) // Without the wavy-dot operator console.log((await asyncArray)) // => 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~.) // => log: 1 console.log(await asyncArray~.length) // => log: 3 console.log(await asyncArray~.join~.('-')) // => log: 1-2-3
Do you think it's useful?