New result error handling operator ?
#3908
Wilbert-mad
started this conversation in
Ideas & suggestions
Replies: 2 comments 2 replies
-
This used to exists; called |
Beta Was this translation helpful? Give feedback.
0 replies
-
What problem does this solve? It seems to be a strictly weaker form of |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Like Rust's
?
operator, there should be a similar way to do what Rust does with its postfix operator in Gleam.Some ideas for the syntax:
They're all quite similar, but the last one may be the best as it follows conventions similar to other operators. I.e
==
,!=
, or>=
.This operator would hand off the error down through and let the developer handle it when needed. For example, In a parser or in a complex build system that returns an error if it fails somewhere in the chain more easily without the need or want to crash, although that goes a bit against BEAM's philosophy of "let it crash".
Under the hood
Under the hood of this operator, it should essentially be like the
use
statement where it takes the remaining (in scope) of the body and compiles it into a case expression.Types
Result(a,e)
When using the
?
operator, like in Rust, it should also require that the expression be of type [named]Result
. As well as, thee
argument be the same as the expression for the outer expression or function, like in Rust.Beta Was this translation helpful? Give feedback.
All reactions