From 63d15086e7f2f8b16548cf614f30dc5feded5573 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 28 May 2022 21:36:13 +0300 Subject: [PATCH] docs: document explicitly, that maps support `if v := m[k] {` too --- doc/docs.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/doc/docs.md b/doc/docs.md index 6d9c347192..f780bde7a9 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -1295,6 +1295,16 @@ mm := map[string]int{} 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: ```v