Standard library / sort

sort.SliceIsSorted()

Checks slice ordering via an index-based callback; panics if x is not a slice. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func SliceIsSorted(x any, less func(i, j int) bool) bool

Parameters & Attributes

NameTypeDescription
xanyInput value or collection to process.
lessfunc(i, j int) boolOrdering callback comparing elements at the given indices.

Return Value

bool

Checks slice ordering via an index-based callback; panics if x is not a slice.

Working Example

Example Snippetgo
package main
import (  "fmt"  "sort")
func main() {  a := []string{"a", "bb"}  fmt.Println(sort.SliceIsSorted(a, func(i, j int) bool { return len(a[i]) < len(a[j]) }))}
Go Reference