diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 66ed81e..4c7f45c 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,4 +1 @@ -# These are supported funding model platforms - -github: rjNemo # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] - +github: rjNemo diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 23ccce4..ea15f39 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -12,12 +12,12 @@ jobs: with: go-version: '1.18' - name: Run tests with coverage - run: go test -race -coverprofile=coverage.out -covermode=atomic ./... + run: go test -coverprofile=coverage.out -covermode=count ./... - uses: codecov/codecov-action@v2 with: - token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos - files: ./coverage.out # optional - flags: unittests # optional - name: codecov-umbrella # optional - fail_ci_if_error: true # optional (default = false) - verbose: true # optional (default = false) \ No newline at end of file + token: ${{ secrets.CODECOV_TOKEN }} + files: ./coverage.out + flags: unittests + name: codecov-umbrella + fail_ci_if_error: true + verbose: true \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 3adecb1..724915b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,8 @@ FROM golang:1.18-alpine ENV CGO_ENABLED 0 +ENV GOOS linux + RUN apk update --no-cache WORKDIR /lib @@ -9,3 +11,4 @@ COPY go.* ./ RUN go mod download COPY . ./ + diff --git a/Makefile b/Makefile index 2ea2d99..daccb29 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ -TEST = "go test ./... -coverpkg=./... -coverprofile coverage.out -covermode=atomic; go tool cover -func coverage.out; rm coverage.out" +TEST = "go test ./... -coverpkg=./... -coverprofile coverage.out -covermode=count; go tool cover -func coverage.out; rm coverage.out" build: - docker build . -t underscore:latest + docker build -t underscore:latest . test: build docker run --name underscore --rm -i -t underscore sh -c $(TEST) diff --git a/docs/themes/compose b/docs/themes/compose index 362af24..94194f5 160000 --- a/docs/themes/compose +++ b/docs/themes/compose @@ -1 +1 @@ -Subproject commit 362af2409158972008f1dff8ee5e887d6ce88257 +Subproject commit 94194f5630e67d3fdbc5d4ae39ac027b0455d29a diff --git a/drop.go b/drop.go new file mode 100644 index 0000000..e572c74 --- /dev/null +++ b/drop.go @@ -0,0 +1,12 @@ +package underscore + +// Drop returns the rest of the elements in a slice. +// Pass an index to return the values of the slice from that index onward. +func Drop[T any](values []T, index int) (rest []T) { + for i, value := range values { + if i != index { + rest = append(rest, value) + } + } + return rest +} diff --git a/drop_test.go b/drop_test.go new file mode 100644 index 0000000..97a187d --- /dev/null +++ b/drop_test.go @@ -0,0 +1,17 @@ +package underscore_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + u "github.com/rjNemo/underscore" +) + +func TestDrop(t *testing.T) { + + nums := []int{1, 9, 2, 8, 3, 7, 4, 6, 5} + want := []int{1, 9, 2, 3, 7, 4, 6, 5} + + assert.Equal(t, want, u.Drop(nums, 3)) +} diff --git a/last.go b/last.go new file mode 100644 index 0000000..d5703a8 --- /dev/null +++ b/last.go @@ -0,0 +1,7 @@ +package underscore + +// Last returns the last element of the slice +func Last[T any](values []T) T { + n := len(values) + return values[n-1] +} diff --git a/last_test.go b/last_test.go new file mode 100644 index 0000000..a0ab085 --- /dev/null +++ b/last_test.go @@ -0,0 +1,15 @@ +package underscore_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + u "github.com/rjNemo/underscore" +) + +func TestLast(t *testing.T) { + nums := []int{1, 9, 2, 8, 3, 7, 4, 6, 5} + want := 5 + assert.Equal(t, want, u.Last(nums)) +}