Standard library / slices
slices.Equal()
Compares length and corresponding elements with ==. Nil and empty slices compare equal; NaN does not equal itself. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func Equal[S ~[]E, E comparable](s1, s2 S) boolParameters & Attributes
| Name | Type | Description |
|---|---|---|
| s1 | S | First slice to compare. |
| s2 | S | Second slice to compare. |
Return Value
bool
Compares length and corresponding elements with ==. Nil and empty slices compare equal; NaN does not equal itself.
Working Example
Example Snippetgo
package main
import ( "fmt" "slices")
func main() { fmt.Println(slices.Equal([]int(nil), []int{}))}