Skip to content

How should I handle none? #23936

Discussion options

You must be logged in to vote

Another way: a is still what V language call, an Option. And a1 is a real integer after using or:

fn main() {
	a, b := foo()
	a1 := a or { -1 } // -1 means default
	println('a: ${a1} b:${b}')
}

fn foo() (?int, string) {
	return none, 'eee'
}
a: -1 b:eee

See https://docs.vlang.io/type-declarations.html#optionresult-types-and-error-handling

Replies: 4 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@jorgeluismireles
Comment options

Answer selected by hellolio
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@jorgeluismireles
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants