Skip to content

Commit

Permalink
Add examples of maps/slices packages
Browse files Browse the repository at this point in the history
  • Loading branch information
eliben committed Aug 22, 2023
1 parent 2166e61 commit 146bd9c
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 15 deletions.
12 changes: 11 additions & 1 deletion examples/maps/maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

package main

import "fmt"
import (
"fmt"
"maps"
)

func main() {

Expand Down Expand Up @@ -58,4 +61,11 @@ func main() {
// the same line with this syntax.
n := map[string]int{"foo": 1, "bar": 2}
fmt.Println("map:", n)

// The `maps` package contains a number of useful
// utility functions for maps.
n2 := map[string]int{"foo": 1, "bar": 2}
if maps.Equal(n, n2) {
fmt.Println("n == n2")
}
}
4 changes: 2 additions & 2 deletions examples/maps/maps.hash
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
b976324013ef31370d1605d1834c5dd6f0db0ea1
6gcPOX9Mm1R
c8435b8cc754213b70c58c9a51dfa824c6f70dd7
5jpkxJ2T0Lv
1 change: 1 addition & 0 deletions examples/maps/maps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ map: map[k1:7]
map: map[]
prs: false
map: map[bar:2 foo:1]
n == n2
12 changes: 11 additions & 1 deletion examples/slices/slices.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

package main

import "fmt"
import (
"fmt"
"slices"
)

func main() {

Expand Down Expand Up @@ -70,6 +73,13 @@ func main() {
t := []string{"g", "h", "i"}
fmt.Println("dcl:", t)

// The `slices` package contains a number of useful
// utility functions for slices.
t2 := []string{"g", "h", "i"}
if slices.Equal(t, t2) {
fmt.Println("t == t2")
}

// Slices can be composed into multi-dimensional data
// structures. The length of the inner slices can
// vary, unlike with multi-dimensional arrays.
Expand Down
4 changes: 2 additions & 2 deletions examples/slices/slices.hash
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
9f1302a9c3cf79e5144c4818ea09465ff8d6da57
553_cYPVlPH
522c14373ae9581dd3001be32530cdf940637646
kiy1StxorBF
1 change: 1 addition & 0 deletions examples/slices/slices.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ sl1: [c d e]
sl2: [a b c d e]
sl3: [c d e f]
dcl: [g h i]
t == t2
2d: [[0] [1 2] [2 3 4]]

# Check out this [great blog post](https://go.dev/blog/slices-intro)
Expand Down
31 changes: 25 additions & 6 deletions public/maps

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

25 changes: 22 additions & 3 deletions public/slices

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

0 comments on commit 146bd9c

Please sign in to comment.