Standard library / slices

slices.EqualFunc()

Compares corresponding elements using a custom equality callback; slices of different element types are supported. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func EqualFunc[S1 ~[]E1, S2 ~[]E2, E1, E2 any](s1 S1, s2 S2, eq func(E1, E2) bool) bool

Parameters & Attributes

NameTypeDescription
s1S1First slice to compare.
s2S2Second slice to compare.
eqfunc(E1, E2) boolEquality callback, true for equivalent elements.

Return Value

bool

Compares corresponding elements using a custom equality callback; slices of different element types are supported.

Working Example

Example Snippetgo
package main
import (  "fmt"  "slices")
func main() {  fmt.Println(slices.EqualFunc([]string{"abc"}, []int{3}, func(s string, n int) bool { return len(s) == n }))}
Go Reference