Skip to content

Commit

Permalink
Add example of the new clear() builtin for maps in 1.21
Browse files Browse the repository at this point in the history
updates #481

Also bump go.mod to 1.21
  • Loading branch information
eliben committed Aug 21, 2023
1 parent 1ee3369 commit d51586e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
5 changes: 5 additions & 0 deletions examples/maps/maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/maps/maps.hash
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
0d764945481b4960c573e67f7d303166b750413e
xl_teZEVqbo
b976324013ef31370d1605d1834c5dd6f0db0ea1
6gcPOX9Mm1R
1 change: 1 addition & 0 deletions examples/maps/maps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ v1: 7
v3: 0
len: 2
map: map[k1:7]
map: map[]
prs: false
map: map[bar:2 foo:1]
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/mmcgrana/gobyexample

go 1.19
go 1.21

require (
github.com/alecthomas/chroma v0.8.2
Expand Down
20 changes: 18 additions & 2 deletions public/maps

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d51586e

Please sign in to comment.