golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
121.11k stars 17.37k forks source link

proposal: x/tools/cmd/eg: support for generics #68070

Open janisz opened 2 weeks ago

janisz commented 2 weeks ago

Proposal Details

It will be great is eg can support generics in a way it can handle e.g. slices of different types.

Example: Replacing a method that takes slices of elements that implements given interface.

package template

import (
        "github.com/golang/protobuf/proto"
        "github.com/stackrox/rox/pkg/protoassert"
        "github.com/stretchr/testify/assert"
        "testing"
)

func before[T proto.Message](t *testing.T, a, b []T) bool {
        return assert.Equal(t, a, b)
}

func after[T proto.Message](t *testing.T, a, b []T) bool {
        return protoassert.SlicesEqual(t, a, b)
}
ianlancetaylor commented 2 weeks ago

CC @alandonovan @golang/tools-team