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) bool

Parameters & Attributes

NameTypeDescription
s1SFirst slice to compare.
s2SSecond 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{}))}
Go Reference