docs: document explicitly, that maps support `if v := m[k] {` too

Delyan Angelov 2022-05-28 21:36:13 +03:00 committed by Chewing_Bever
parent 8cecea9965
commit 0a3d41c5d7
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
1 changed files with 10 additions and 0 deletions

View File

@ -1295,6 +1295,16 @@ mm := map[string]int{}
val := mm['bad_key'] or { panic('key not found') } val := mm['bad_key'] or { panic('key not found') }
``` ```
You can also check, if a key is present, and get its value, if it was present, in one go:
```v
m := {
'abc': 'def'
}
if v := m['abc'] {
println('the map value for that key is: $v')
}
```
The same optional check applies to arrays: The same optional check applies to arrays:
```v ```v