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

We want to signify that it’s not a normal assignment. It’s an operation with two possibilities:

  1. Unwrapping on success or
  2. Return on error.

To me the following options read better:

Modifying the assignment operator

let Ok(user) ?= await fetchUser(id)

Modifying the right hand side expression of the assignment, which can either return a value or Error.

let Ok(user) = await fetchUser(id) ?

But that would mess with the ternary operator syntax.

Or like @hellos3b suggested, having the question mark on the unwrapper:

let Ok(user)? = await fetchUser(id)

The maybe keyword by @YKW is very appealing from a reader’s perspective as well.
I am not a fan of the let? as well - it lends a cryptic vibe to the language. We should strive to have an extremely readable syntax.


Viewing all articles
Browse latest Browse all 2592

Trending Articles