Skip to content
Merged

drop #18

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 7 additions & 7 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.out
flags: unittests
name: codecov-umbrella
fail_ci_if_error: true
verbose: true
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
FROM golang:1.18-alpine

ENV CGO_ENABLED 0
ENV GOOS linux

RUN apk update --no-cache

WORKDIR /lib
Expand All @@ -9,3 +11,4 @@ COPY go.* ./
RUN go mod download

COPY . ./

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion docs/themes/compose
12 changes: 12 additions & 0 deletions drop.go
Original file line number Diff line number Diff line change
@@ -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
}
17 changes: 17 additions & 0 deletions drop_test.go
Original file line number Diff line number Diff line change
@@ -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))
}
7 changes: 7 additions & 0 deletions last.go
Original file line number Diff line number Diff line change
@@ -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]
}
15 changes: 15 additions & 0 deletions last_test.go
Original file line number Diff line number Diff line change
@@ -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))
}