-
Notifications
You must be signed in to change notification settings - Fork 55
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
Ignore order when comparing equality of slices/maps #28
Comments
Can you give an example of what you'd like to see for both? Order shouldn't matter for maps, but it's inherent to slices. |
I think there should be an option for slices; sometimes order is matter; sometimes doesn't. But maps are unordered by default |
+1 for this I have a use case where I am testing a slice that results from go routines and the order varies. Maybe the method signature can use flags? Equal(a, b interface{}, ...flags interface{}) deep.Equal([]string{"hello", "world"}, []string{"world", "hello"}, deep.FLAG_IGNORE_SLICE_ORDER) |
It's inherent to the data structure, but not inherent from the perspective of the user. Sometimes people use slices as an unordered list, sometimes they use them as ordered lists. If you are dealing with a lot of data mangling and manipulation because of the restrictiveness of Go's type system (and it will be years before most libraries switch to using implementation with generics now that 1.18 has come out), then it's a massive pain point. A case in point is the generated go code from Protobuf definitions, which can be an absolute nightmare to deal with if you need to do any kind of validation between definitions in separate files, especially when the underlying values of the objects being compared are absolutely identical. If you look at the |
It's been a few years, but better late than never: implemented in #56 and will be released as v1.1.0 since it's a relatively major addition even though it's backwards compatible. |
Thank you, Daniel! |
It would be great to have option to ignore order of items in slices/maps and just assert that it contains the same element.
The text was updated successfully, but these errors were encountered: