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

Refactor reflect.DeepEqual to slices.Equal from the standard lib #721

Open
konsalex opened this issue Dec 13, 2023 · 1 comment
Open

Refactor reflect.DeepEqual to slices.Equal from the standard lib #721

konsalex opened this issue Dec 13, 2023 · 1 comment

Comments

@konsalex
Copy link

Hey folks,

Would it make sense to add also the new way to compare slices in this chapter: https://quii.gitbook.io/learn-go-with-tests/go-fundamentals/arrays-and-slices#write-enough-code-to-make-it-pass-4

So instead of using reflect.DeepEqual to use slices.Equal.

I could make a contribution to add this

@dario-piotrowicz
Copy link
Contributor

The guide does mention slices.Equal here:

(From Go 1.21, [slices](https://pkg.go.dev/slices#pkg-overview) standard package is available, which has [slices.Equal](https://pkg.go.dev/slices#Equal) function to do a simple shallow compare on slices, where you don't need to worry about the types like the above case. Note that this function expects the elements to be [comparable](https://pkg.go.dev/builtin#comparable). So, it can't be applied to slices with non-comparable elements like 2D slices.)

And go 1.21 has been out for a while: https://go.dev/doc/devel/release#go1.21.0

So I think it could make sense 🤔

but I am not sure, maybe the guide tries to make zero assumptions on the go version being used? 🤷

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

No branches or pull requests

2 participants