-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexample_test.go
75 lines (62 loc) · 1.26 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package mapset_test
import (
"fmt"
"strings"
"github.com/creachadair/mds/mapset"
)
func Example() {
s := mapset.New(strings.Fields("a man a plan")...)
// Add individual elements.
s.Add("panama", "canal")
// Add the contents of another set.
t := mapset.New("plan", "for", "the", "future")
s.AddAll(t)
// Remove items and convert to a slice.
elts := s.Remove("a", "an", "the", "for").Slice()
// Clone and make other changes.
u := s.Clone().Remove("future", "plans")
// Do some basic comparisons.
fmt.Println("t intersects u:", t.Intersects(u))
fmt.Println("t equals u:", t.Equals(u))
fmt.Println()
// The slice is unordered, so impose some discipline.
fmt.Println(strings.Join(elts, "\n"))
// Unordered output:
// t intersects u: true
// t equals u: false
//
// canal
// future
// man
// panama
// plan
}
func ExampleKeys() {
s := mapset.Keys(map[string]int{
"apple": 1,
"pear": 2,
"plum": 3,
"cherry": 4,
})
fmt.Println(strings.Join(s.Slice(), "\n"))
// Unordered output:
// apple
// cherry
// pear
// plum
}
func ExampleValues() {
s := mapset.Values(map[string]int{
"apple": 5,
"pear": 4,
"plum": 4,
"cherry": 6,
})
for _, v := range s.Slice() {
fmt.Println(v)
}
// Unordered output:
// 4
// 5
// 6
}