Standard library / slices

slices.IsSortedFunc()

Checks ordering according to the supplied strict weak ordering comparator. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func IsSortedFunc[S ~[]E, E any](x S, cmp func(a, b E) int) bool

Parameters & Attributes

NameTypeDescription
xSInput value or collection to process.
cmpfunc(a, b E) intComparison callback; negative, zero, or positive for less, equivalent, or greater.

Return Value

bool

Checks ordering according to the supplied strict weak ordering comparator.

Working Example

Example Snippetgo
package main
import (  "cmp"  "fmt"  "slices")
func main() {  fmt.Println(slices.IsSortedFunc([]string{"a", "bb"}, func(a, b string) int { return cmp.Compare(len(a), len(b)) }))}
Go Reference