How should I handle none? #23936
-
I know there is an issue with this code, but I'm not sure how to fix it. Please tell me what to do. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
forgive me, this is a very basic question. i am learning it |
Beta Was this translation helpful? Give feedback.
-
Something like this?: fn main() {
a, b := foo()
if a == none {
println('a: default')
} else {
println('a: ${a}')
}
println('b: ${b}')
}
fn foo() (?int, string) {
return none, 'eee'
}
A good place to practice is here: https://play.vlang.io/p/296a95059b |
Beta Was this translation helpful? Give feedback.
-
@jorgeluismireles |
Beta Was this translation helpful? Give feedback.
-
@jorgeluismireles |
Beta Was this translation helpful? Give feedback.
Another way:
a
is still what V language call, an Option. Anda1
is a real integer after usingor
:See https://docs.vlang.io/type-declarations.html#optionresult-types-and-error-handling