Skip to content

Instantly share code, notes, and snippets.

@bmeck
Created February 14, 2024 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmeck/a46a75303e73b49ea33abef65d3f024c to your computer and use it in GitHub Desktop.
Save bmeck/a46a75303e73b49ea33abef65d3f024c to your computer and use it in GitHub Desktop.

If you have ever had to deal with Promise heavy code, and in particular deep data structures you will likely be familiar with code like the following:

const body = await (await fetch(url)).json()

This has a LHS RHS interchange that causes non-linear edits while writing code (especially with autocomplete):

fetch(url) // LTR
await fetch(url) // RTL, never seen autocomplete LHS await
await fetch(url).json() // Don't get autocomplete, don't .json(), BUG TO GO LTR need towrap
(await fetch(url)) // BOTH
(await fetch(url)).json() // LTR
await (await fetch(url)).json() // RTL

Compare with an eventual send approach of postfix based processing:

let body = fetch(url)~>.json()~>await
fetch(url)
// completion provider can give/discover .json -> ~>.json
fetch(url)~>.json()
// completion provider can give await completion
fetch(url)~>.json()~>await
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment