Skip to content

Commit df4f8e3

Browse files
committed
add examples for rest
1 parent d5ffd47 commit df4f8e3

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ __pycache__/
55
.vscode
66
.swp
77
*~
8+
.task

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ codes := slices.MapAsync(
7272

7373
Genesis contains the following packages:
7474

75-
+ [🍞 slices](https://pkg.go.dev/github.com/life4/genesis/slices): generic functions for slices.
76-
+ [🗺 maps](https://pkg.go.dev/github.com/life4/genesis/maps): generic functions for maps.
77-
+ [📺 channels](https://pkg.go.dev/github.com/life4/genesis/channels): generic function for channels.
75+
+ [🍞 slices](https://pkg.go.dev/github.com/life4/genesis/slices): generic functions for slices (`[]T`).
76+
+ [🗺 maps](https://pkg.go.dev/github.com/life4/genesis/maps): generic functions for maps (`map[K]V`).
77+
+ [📺 channels](https://pkg.go.dev/github.com/life4/genesis/channels): generic function for channels (`chan T`).
78+
+ [⚙️ sets](https://pkg.go.dev/github.com/life4/genesis/sets): generic function for sets (`map[T]struct{}`).
7879
+ [🛟 lambdas](https://pkg.go.dev/github.com/life4/genesis/lambdas): helper generic functions to work with `slices.Map` and similar.
7980

8081
See [📄 DOCUMENTATION](https://pkg.go.dev/github.com/life4/genesis) for more info.

doc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ import (
66
_ "github.com/life4/genesis/channels"
77
_ "github.com/life4/genesis/lambdas"
88
_ "github.com/life4/genesis/maps"
9+
_ "github.com/life4/genesis/sets"
910
_ "github.com/life4/genesis/slices"
1011
)

sets/example_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,28 @@ func ExampleIntersect() {
6262
// Output: true
6363
}
6464

65+
func ExampleMax() {
66+
s := sets.New(3, 6, 4, 5)
67+
result, _ := sets.Max(s)
68+
fmt.Println(result)
69+
// Output: 6
70+
}
71+
72+
func ExampleMin() {
73+
s := sets.New(4, 5, 3, 6)
74+
result, _ := sets.Min(s)
75+
fmt.Println(result)
76+
// Output: 3
77+
}
78+
79+
func ExampleReduce() {
80+
s := sets.New(3, 4, 5)
81+
add := func(x, acc int) int { return x + acc }
82+
result := sets.Reduce(s, 0, add)
83+
fmt.Println(result)
84+
// Output: 12
85+
}
86+
6587
func ExampleSubset() {
6688
a := sets.New(4, 5)
6789
b := sets.New(3, 4, 5, 6)
@@ -70,6 +92,20 @@ func ExampleSubset() {
7092
// Output: true
7193
}
7294

95+
func ExampleSum() {
96+
s := sets.New(3, 4, 5)
97+
result := sets.Sum(s)
98+
fmt.Println(result)
99+
// Output: 12
100+
}
101+
102+
func ExampleToSlice() {
103+
s := sets.New(3)
104+
result := sets.ToSlice(s)
105+
fmt.Println(result)
106+
// Output: [3]
107+
}
108+
73109
func ExampleSuperset() {
74110
a := sets.New(3, 4, 5, 6)
75111
b := sets.New(4, 5)

0 commit comments

Comments
 (0)