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) boolParameters & Attributes
| Name | Type | Description |
|---|---|---|
| x | any | Input value or collection to process. |
| less | func(i, j int) bool | Ordering 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]) }))}