Can Option and Result be used together? #21793
Replies: 2 comments
-
No, they cannot. There used to only be one type, that incorporated both, but too many people complained that it was too "hard" to distinguish. They actually needed to put an So now, they are 2 separate types which cannot be used together. The simplest way to get the effects of both is to use a Result type, and send back a specific error for |
Beta Was this translation helpful? Give feedback.
-
V's documentation gives 4 examples of usage. Perhaps that should be the reference point to start from, concerning possible issues. |
Beta Was this translation helpful? Give feedback.
-
Example A
Suppose we have Lisp/Haskell style lists, and are writing a function to return the tail of the list.
none
.Example B
We have a function that constructs binary trees
What is the idiomatic way to address such scenarios? Are there examples in the standard library I should look at?
Beta Was this translation helpful? Give feedback.
All reactions