mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
Enable Gofmt Linting via Golang-CI Lint to Allow for Generic Code in Prysm (#11205)
* converting to generic * enable gofmt linting * enable gofmt Co-authored-by: James He <james@prysmaticlabs.com> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
@@ -365,12 +365,12 @@ func IsInSlots(a types.Slot, b []types.Slot) bool {
|
||||
}
|
||||
|
||||
// Unique returns an array with duplicates filtered based on the type given
|
||||
func Unique(a []string) []string {
|
||||
func Unique[T comparable](a []T) []T {
|
||||
if a == nil || len(a) <= 1 {
|
||||
return a
|
||||
}
|
||||
found := map[string]bool{}
|
||||
result := make([]string, len(a))
|
||||
found := map[T]bool{}
|
||||
result := make([]T, len(a))
|
||||
end := 0
|
||||
for i := 0; i < len(a); i++ {
|
||||
if !found[a[i]] {
|
||||
|
||||
@@ -591,7 +591,11 @@ func TestIsInSlots(t *testing.T) {
|
||||
|
||||
func TestUnique(t *testing.T) {
|
||||
t.Run("string", func(t *testing.T) {
|
||||
result := slice.Unique([]string{"a", "b", "a"})
|
||||
result := slice.Unique[string]([]string{"a", "b", "a"})
|
||||
require.DeepEqual(t, []string{"a", "b"}, result)
|
||||
})
|
||||
t.Run("uint64", func(t *testing.T) {
|
||||
result := slice.Unique[uint64]([]uint64{1, 2, 1})
|
||||
require.DeepEqual(t, []uint64{1, 2}, result)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user