-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmightymap_example_test.go
62 lines (54 loc) · 1.32 KB
/
mightymap_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
package mightymap_test
import (
"fmt"
"slices"
"strings"
"github.com/thisisdevelopment/mightymap"
"github.com/thisisdevelopment/mightymap/storage"
)
func ExampleMap() {
cm := mightymap.New[int, string](true)
cm.Store(ctx, 1, "one")
fmt.Println(cm.Load(ctx, 1))
// Output: one true
}
func ExampleMap_Load() {
// Using Badger storage
// Load example
cm := mightymap.New[int, string](true, storage.NewMightyMapBadgerStorage[int, string]())
cm.Store(ctx, 1, "one")
fmt.Println(cm.Load(ctx, 1))
// Output: one true
}
func ExampleMap_Next() {
// Using Badger storage
// Next example
cm := mightymap.New[int, string](true, storage.NewMightyMapBadgerStorage[int, string]())
cm.Store(ctx, 1, "one")
fmt.Println(cm.Next(ctx))
// Output: one 1 true
}
func ExampleMap_Range() {
cm := mightymap.New[int, string](true)
cm.Store(ctx, 1, "one")
cm.Store(ctx, 2, "two")
values := []string{}
cm.Range(ctx, func(key int, value string) bool {
values = append(values, value)
return true
})
slices.Sort(values)
fmt.Println(strings.Join(values, "\n"))
// Output:
// one
// two
}
func ExampleMap_Delete() {
cm := mightymap.New[int, string](true)
cm.Store(ctx, 1, "one")
cm.Store(ctx, 2, "two")
cm.Delete(ctx, 1, 2)
value, ok := cm.Load(ctx, 1)
fmt.Printf("Value: %v, OK: %v\n", value, ok)
// Output: Value: , OK: false
}