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) boolParameters & Attributes
| Name | Type | Description |
|---|---|---|
| x | S | Input value or collection to process. |
| cmp | func(a, b E) int | Comparison 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)) }))}