From dd7dc8509a3debc2a9325d2f68984a0f83ab3d1a Mon Sep 17 00:00:00 2001 From: Thuc Le Date: Tue, 15 Mar 2022 19:27:11 +0100 Subject: [PATCH] bug: correct pipeline, contraints package and example functions --- .github/workflows/build.yml | 5 +---- README.md | 2 +- constraints.go | 2 +- count.go | 2 +- count_list.go | 2 +- every_test.go | 2 +- exist_test.go | 2 +- filter_test.go | 2 +- find_test.go | 2 +- flat_test.go | 2 +- foreach_test.go | 2 +- go.mod | 2 ++ go.sum | 2 ++ group_test.go | 2 +- map_test.go | 2 +- max.go | 2 +- min.go | 2 +- mode.go | 2 +- reduce_right_test.go | 2 +- reduce_test.go | 2 +- some_test.go | 2 +- 21 files changed, 23 insertions(+), 22 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 11e990e..cbba331 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,16 +18,13 @@ jobs: - name: Install dependencies run: | go version - cd server; go mod tidy + go mod tidy - name: Run build run: | - cd server go build . - name: Run testing run: | - cd server go test -v - name: Run vetting run: | - cd server go vet -v ./... diff --git a/README.md b/README.md index 3565a36..1b4215f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Goterators -[![Built with WeBuild](https://raw.githubusercontent.com/webuild-community/badge/master/svg/WeBuild.svg)](https://webuild.community) [![Go Reference](https://pkg.go.dev/badge/github.com/ledongthuc/goterators.svg)](https://pkg.go.dev/github.com/ledongthuc/goterators) +[![Built with WeBuild](https://raw.githubusercontent.com/webuild-community/badge/master/svg/WeBuild.svg)](https://webuild.community) [![Go Reference](https://pkg.go.dev/badge/github.com/ledongthuc/goterators.svg)](https://pkg.go.dev/github.com/ledongthuc/goterators) [![goterators-Build](https://github.com/ledongthuc/goterators/actions/workflows/build.yml/badge.svg)](https://github.com/ledongthuc/goterators/actions/workflows/build.yml) ![goterators-Thumbnail](https://user-images.githubusercontent.com/1828895/147876484-5bc7cfd0-5f14-4889-a3f0-64cb307b7765.png) diff --git a/constraints.go b/constraints.go index cb33a71..ab34cfc 100644 --- a/constraints.go +++ b/constraints.go @@ -1,6 +1,6 @@ package goterators -import "constraints" +import "golang.org/x/exp/constraints" type Number interface { constraints.Integer | constraints.Float diff --git a/count.go b/count.go index edf9d1b..d980537 100644 --- a/count.go +++ b/count.go @@ -1,6 +1,6 @@ package goterators -import "constraints" +import "golang.org/x/exp/constraints" // Count returns number of checking item exists in source list func Count[T constraints.Ordered](source []T, checkedItem T) (result int) { diff --git a/count_list.go b/count_list.go index 9a7dc1e..c92baf3 100644 --- a/count_list.go +++ b/count_list.go @@ -1,6 +1,6 @@ package goterators -import "constraints" +import "golang.org/x/exp/constraints" // CountList returns sub-list counter of input sub-list that want to count from source list. func CountList[T constraints.Ordered](source []T, checkedItems []T) []int { diff --git a/every_test.go b/every_test.go index e6bf85e..9f1f3b5 100644 --- a/every_test.go +++ b/every_test.go @@ -25,7 +25,7 @@ func TestEveryNotValid(t *testing.T) { } } -func ExampleEvery(t *testing.T) { +func ExampleEvery() { testSource := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} everyValid := Every(testSource, func(item int) bool { return item <= 20 }) fmt.Println("Every: ", everyValid) diff --git a/exist_test.go b/exist_test.go index 11d1c9d..4d688d5 100644 --- a/exist_test.go +++ b/exist_test.go @@ -33,7 +33,7 @@ func TestExistString(t *testing.T) { } } -func ExampleExist(t *testing.T) { +func ExampleExist() { testSource := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} fmt.Println("Exist: ", Exist(testSource, 15)) } diff --git a/filter_test.go b/filter_test.go index 6d8d4ab..3ed02e4 100644 --- a/filter_test.go +++ b/filter_test.go @@ -40,7 +40,7 @@ func TestFilterString(t *testing.T) { } } -func ExampleFilter(t *testing.T) { +func ExampleFilter() { testSource := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} filteredItems := Filter(testSource, func(item int) bool { return item%2 == 0 diff --git a/find_test.go b/find_test.go index b7c8109..07c954d 100644 --- a/find_test.go +++ b/find_test.go @@ -59,7 +59,7 @@ func TestFindString(t *testing.T) { } } -func ExampleFind(t *testing.T) { +func ExampleFind() { testSource := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} firstFoundItem, index, _ := Find(testSource, func(item int) bool { return item%10 == 0 diff --git a/flat_test.go b/flat_test.go index 9e10df3..bf1cca4 100644 --- a/flat_test.go +++ b/flat_test.go @@ -41,7 +41,7 @@ func TestFlatNested(t *testing.T) { } } -func ExampleFlat(t *testing.T) { +func ExampleFlat() { testSource := [][]int{{1, 2, 3, 4}, {5, 6, 7, 8, 9, 10, 11}, {12, 13, 14, 15, 16, 17, 18, 19}, {20}, {}} items := Flat(testSource) fmt.Println("Flat: ", items) diff --git a/foreach_test.go b/foreach_test.go index 40c1cb9..991f50e 100644 --- a/foreach_test.go +++ b/foreach_test.go @@ -27,7 +27,7 @@ func testForEach[K comparable](source []K, t *testing.T) { } } -func ExampleForEach(t *testing.T) { +func ExampleForEach() { testSource := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} ForEach(testSource, func(item int) { fmt.Println("ForEach: ", item) diff --git a/go.mod b/go.mod index fb02aa1..c9044d2 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/ledongthuc/goterators go 1.18 + +require golang.org/x/exp v0.0.0-20220314205449-43aec2f8a4e7 // indirect diff --git a/go.sum b/go.sum index e69de29..033310c 100644 --- a/go.sum +++ b/go.sum @@ -0,0 +1,2 @@ +golang.org/x/exp v0.0.0-20220314205449-43aec2f8a4e7 h1:jynE66seADJbyWMUdeOyVTvPtBZt7L6LJHupGwxPZRM= +golang.org/x/exp v0.0.0-20220314205449-43aec2f8a4e7/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE= diff --git a/group_test.go b/group_test.go index bc5f455..e6299ac 100644 --- a/group_test.go +++ b/group_test.go @@ -62,7 +62,7 @@ func TestGroup(t *testing.T) { } } -func ExampleGroup(t *testing.T) { +func ExampleGroup() { testSource := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} groups := Group(testSource, func(item int) int { return item % 2 diff --git a/map_test.go b/map_test.go index 6cee044..4ff303f 100644 --- a/map_test.go +++ b/map_test.go @@ -30,7 +30,7 @@ func TestMap(t *testing.T) { } } -func ExampleMap(t *testing.T) { +func ExampleMap() { testSource := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} mappedItems := Map(testSource, func(item int) string { return fmt.Sprintf("Item-%d", item) diff --git a/max.go b/max.go index 13278c8..f34b838 100644 --- a/max.go +++ b/max.go @@ -1,6 +1,6 @@ package goterators -import "constraints" +import "golang.org/x/exp/constraints" // Max find largest value from source list func Max[T constraints.Ordered](source []T) (result T, err error) { diff --git a/min.go b/min.go index ea6d7b8..efbb412 100644 --- a/min.go +++ b/min.go @@ -1,6 +1,6 @@ package goterators -import "constraints" +import "golang.org/x/exp/constraints" // Min find smallest value from source list func Min[T constraints.Ordered](source []T) (result T, err error) { diff --git a/mode.go b/mode.go index 96cac72..5865c8a 100644 --- a/mode.go +++ b/mode.go @@ -1,6 +1,6 @@ package goterators -import "constraints" +import "golang.org/x/exp/constraints" // Mode return a value that appears most often in the source list. func Mode[T constraints.Ordered](source []T) (T, int) { diff --git a/reduce_right_test.go b/reduce_right_test.go index 2ae012e..0873072 100644 --- a/reduce_right_test.go +++ b/reduce_right_test.go @@ -22,7 +22,7 @@ func TestReduceRight(t *testing.T) { } } -func ExampleReduceRight(t *testing.T) { +func ExampleReduceRight() { testSource := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} result := ReduceRight(testSource, []int{}, func(previous []int, current int, index int, list []int) []int { return append(previous, current) diff --git a/reduce_test.go b/reduce_test.go index a35578c..a89aedc 100644 --- a/reduce_test.go +++ b/reduce_test.go @@ -34,7 +34,7 @@ func TestReduceSimulateMap(t *testing.T) { } } -func ExampleReduce(t *testing.T) { +func ExampleReduce() { testSource := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} result := Reduce(testSource, 0, func(previous int, current int, index int, list []int) int { return previous + current diff --git a/some_test.go b/some_test.go index 07e339d..28fb9fe 100644 --- a/some_test.go +++ b/some_test.go @@ -25,7 +25,7 @@ func TestSomeNotValid(t *testing.T) { } } -func ExampleSome(t *testing.T) { +func ExampleSome() { testSource := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} result := Some(testSource, func(item int) bool { return item%2 == 0