google / google/go-cmp

Ideas for a v2

Open
#338 4 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
4.7k
Forks
243
PR merge metrics
No merged PRs in 30d

Description

Overall, this package has held up well.
If we were to ever consider a v2, here are some changes:

* By default, always treat every variable as addressable, so that comparers and transformers that operate on a pointer can be used.
* Use generics where appropriate:
```go
package cmp
func Comparer[T any](f func(T, T) bool) Option
func FilterValues[T any](f func(T, T) bool) Option
func Transformer[T, R any](name string, f func(T) R) Option
```
```go
package cmpopts
func AcyclicTransformer[T, R any](name string, f func(T) R) Option
func IgnoreFields[T any](names ...string) Option
func IgnoreInterface[T any]() Option
func IgnoreMapEntries[K comparable, V any](f func(K, V) bool) Option
func IgnoreSliceElements[E any](f func(E) bool) Option
func IgnoreType[T any]() Option
func IgnoreUnexported[T any]() Option
func SortMaps[K comparable](f func(K, K) bool) Option
func SortSlices[T any](f func(T, T) bool) Option
```
It's unclear whether `SortMaps` and `SortSlices` should take a less function (i.e., `func(T, T) bool`) or a compare function (i.e., `func(T, T) int`) to match the current `slices.SortFunc` signature.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.