Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Proposing new syntax for zero-cost unwrapping options/results

$
0
0

I very much like the originally proposed version.

Comparing

let? Ok(user) = await fetchUser(id)
let? Ok(decodedUser) = decodeUser(user)
let? Ok() = await ensureUserActive(decodedUser)
let someThingElse = ...

to something like

let Ok(user) ?= await fetchUser(id)
let Ok(decodedUser) ?= decodeUser(user)
let Ok() ?= await ensureUserActive(decodedUser)
let someThingElse = ...

I find that

  1. In the first version, when reading the code, I can see at the very first glance which lets are “normal” lets and which are not, without having to scan further to the right.
  2. In the first version, the ? are neatly stacked below each other. (And I think it will be a very frequent use case to have multiple lines with let? “stacked” like in the example.)

I also think that the ? is a good choice compared to other characters as it is familiar for dealing with options (optional chaining) in TypeScript.


Viewing all articles
Browse latest Browse all 2592

Trending Articles