Add examples of maps/slices packages
This commit is contained in:
@@ -3,7 +3,10 @@
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"maps"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
b976324013ef31370d1605d1834c5dd6f0db0ea1
|
||||
6gcPOX9Mm1R
|
||||
c8435b8cc754213b70c58c9a51dfa824c6f70dd7
|
||||
5jpkxJ2T0Lv
|
||||
|
||||
@@ -9,3 +9,4 @@ map: map[k1:7]
|
||||
map: map[]
|
||||
prs: false
|
||||
map: map[bar:2 foo:1]
|
||||
n == n2
|
||||
|
||||
@@ -3,7 +3,10 @@
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
9f1302a9c3cf79e5144c4818ea09465ff8d6da57
|
||||
553_cYPVlPH
|
||||
522c14373ae9581dd3001be32530cdf940637646
|
||||
kiy1StxorBF
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user