Skip to content

Commit

Permalink
Update arrays-and-slices.md: Improved slices package tip with compara…
Browse files Browse the repository at this point in the history
…ble (#724)
  • Loading branch information
swamisriman authored Dec 23, 2023
1 parent aa14392 commit 178c1cf
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions arrays-and-slices.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,9 @@ func TestSumAll(t *testing.T) {
What we have done here is try to compare a `slice` with a `string`. This makes
no sense, but the test compiles! So while using `reflect.DeepEqual` is
a convenient way of comparing slices \(and other things\) you must be careful
when using it.
(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.)
when using it.

(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.)

Change the test back again and run it. You should have test output like the following

Expand Down

0 comments on commit 178c1cf

Please sign in to comment.