Skip to content

Commit

Permalink
Remove 'tfslices.Chunks'.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Sep 4, 2024
1 parent 281ea60 commit e5c24d5
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 56 deletions.
17 changes: 0 additions & 17 deletions internal/slices/slices.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,6 @@ func Any[S ~[]E, E any](s S, f Predicate[E]) bool {
return false
}

// Chunks returns a slice of S, each of the specified size (or less).
func Chunks[S ~[]E, E any](s S, size int) []S {
chunks := make([]S, 0)

for i := 0; i < len(s); i += size {
end := i + size

if end > len(s) {
end = len(s)
}

chunks = append(chunks, s[i:end])
}

return chunks
}

// AppendUnique appends unique (not already in the slice) values to a slice.
func AppendUnique[S ~[]E, E comparable](s S, vs ...E) S {
for _, v := range vs {
Expand Down
39 changes: 0 additions & 39 deletions internal/slices/slices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,45 +153,6 @@ func TestApplyToAll(t *testing.T) {
}
}

func TestChunk(t *testing.T) {
t.Parallel()

type testCase struct {
input []string
expected [][]string
}
tests := map[string]testCase{
"three elements": {
input: []string{"one", "two", "3"},
expected: [][]string{{"one", "two"}, {"3"}},
},
"two elements": {
input: []string{"aa", "bb"},
expected: [][]string{{"aa", "bb"}},
},
"one element": {
input: []string{"1"},
expected: [][]string{{"1"}},
},
"zero elements": {
input: []string{},
expected: [][]string{},
},
}

for name, test := range tests {
t.Run(name, func(t *testing.T) {
t.Parallel()

got := Chunks(test.input, 2)

if diff := cmp.Diff(got, test.expected); diff != "" {
t.Errorf("unexpected diff (+wanted, -got): %s", diff)
}
})
}
}

func TestFilter(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit e5c24d5

Please sign in to comment.