doc: add that `or` blocks may end with default values
parent
f61a7bf3df
commit
87a0765ce4
10
doc/docs.md
10
doc/docs.md
|
@ -1373,8 +1373,14 @@ fn (r Repo) find_user_by_id(id int) ?User {
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
repo := new_repo()
|
repo := new_repo()
|
||||||
user := repo.find_user_by_id(10) or { // Option types must be handled by `or` blocks
|
user := repo.find_user_by_id(10) or {
|
||||||
return // `or` block must end with `return`, `break`, or `continue`
|
// Option types must be handled by `or` blocks.
|
||||||
|
// Any `or` block, *must* end with one of:
|
||||||
|
// a) `break`, `continue` or `return` .
|
||||||
|
// b) a panic("message") or exit(code) call .
|
||||||
|
// c) a default value of the same type as the Option .
|
||||||
|
// (i.e. if the function returns for example ?int, you may put 1234 as default value)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
println(user.id) // "10"
|
println(user.id) // "10"
|
||||||
println(user.name) // "Charles"
|
println(user.name) // "Charles"
|
||||||
|
|
Loading…
Reference in New Issue