diff --git a/examples/maps/maps.go b/examples/maps/maps.go index 441e2a3..79db901 100644 --- a/examples/maps/maps.go +++ b/examples/maps/maps.go @@ -39,6 +39,11 @@ func main() { delete(m, "k2") fmt.Println("map:", m) + // To remove *all* key/value pairs from a map, use + // the `clear` builtin. + clear(m) + fmt.Println("map:", m) + // The optional second return value when getting a // value from a map indicates if the key was present // in the map. This can be used to disambiguate diff --git a/examples/maps/maps.hash b/examples/maps/maps.hash index 9dcd6b8..d6abb5d 100644 --- a/examples/maps/maps.hash +++ b/examples/maps/maps.hash @@ -1,2 +1,2 @@ -0d764945481b4960c573e67f7d303166b750413e -xl_teZEVqbo +b976324013ef31370d1605d1834c5dd6f0db0ea1 +6gcPOX9Mm1R diff --git a/examples/maps/maps.sh b/examples/maps/maps.sh index 56f3be1..2b24dbb 100644 --- a/examples/maps/maps.sh +++ b/examples/maps/maps.sh @@ -6,5 +6,6 @@ v1: 7 v3: 0 len: 2 map: map[k1:7] +map: map[] prs: false map: map[bar:2 foo:1] diff --git a/go.mod b/go.mod index 7efb899..08c82c0 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/mmcgrana/gobyexample -go 1.19 +go 1.21 require ( github.com/alecthomas/chroma v0.8.2 diff --git a/public/maps b/public/maps index 8e64a84..b3e0fe8 100644 --- a/public/maps +++ b/public/maps @@ -42,7 +42,7 @@ - +
package main
 
@@ -172,6 +172,21 @@ a map.

+ + +

To remove all key/value pairs from a map, use +the clear builtin.

+ + + + +
+    clear(m)
+    fmt.Println("map:", m)
+
+ + +

The optional second return value when getting a @@ -227,6 +242,7 @@ printed with fmt.Println.

v3: 0 len: 2 map: map[k1:7] +map: map[] prs: false map: map[bar:2 foo:1] @@ -247,7 +263,7 @@ printed with fmt.Println.