Skip to content

Commit

Permalink
Drop unused Remove* utils functions
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed May 31, 2024
1 parent f0074b8 commit d1afa6d
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 41 deletions.
19 changes: 0 additions & 19 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,25 +139,6 @@ func ToDBInt(value int64) types.Int {
return val
}

func RemoveIf[T any](slice []T, pred func(T) bool) []T {
n := len(slice)

for i := 0; i < n; i++ {
for i < n && pred(slice[i]) {
n--
slice[i], slice[n] = slice[n], slice[i]
}
}

return slice[:n]
}

func RemoveNils[T any](slice []*T) []*T {
return RemoveIf(slice, func(ptr *T) bool {
return ptr == nil
})
}

// IterateOrderedMap implements iter.Seq2 to iterate over a map in the key's order.
//
// This function returns a func yielding key-value-pairs from a given map in the order of their keys, if their type
Expand Down
22 changes: 0 additions & 22 deletions internal/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,6 @@ import (
"testing"
)

func TestRemoveNils(t *testing.T) {
var a, b, c, d int

tests := []struct {
name string
in []*int
want []*int
}{
{"Empty", []*int{}, []*int{}},
{"SingleKeep", []*int{&a}, []*int{&a}},
{"SingleRemove", []*int{nil}, []*int{}},
{"KeepOrder", []*int{&a, &b, &c, &d}, []*int{&a, &b, &c, &d}},
{"Duplicates", []*int{&a, &b, &b}, []*int{&a, &b, &b}},
{"Mixed", []*int{&a, nil, &b, nil, nil, &b, nil, &d}, []*int{&a, &b, &b, &d}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, RemoveNils(tt.in))
})
}
}

func TestIterateOrderedMap(t *testing.T) {
tests := []struct {
name string
Expand Down

0 comments on commit d1afa6d

Please sign in to comment.