Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ideas for a v2 #338

Open
dsnet opened this issue Aug 26, 2023 · 3 comments
Open

Ideas for a v2 #338

dsnet opened this issue Aug 26, 2023 · 3 comments

Comments

@dsnet
Copy link
Collaborator

dsnet commented Aug 26, 2023

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:
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
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.

@dprotaso
Copy link

dprotaso commented Oct 6, 2023

It would be good if we could control whether the library panics or returns an error -

Knative has wrapped this library to handle that
https://github.com/knative/pkg/blob/d0a82f9cbb8f2f92ce8f130c701f2da29bb33109/kmp/diff.go#L41

@Sung123zaaaa
Copy link

#338 (comment)

@zchee
Copy link

zchee commented Nov 23, 2023

@dsnet
v2 is roughly accepts backwards incompatible change.
So would be happy if rename cmp package name to something (e.g., gocmp, or gcmp means Google Compare library...?) for conflicts stdlib cmp package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants