Skip to content
masterclass Buddy

Go · Interface

sort.Interface

sort.Interface is the contract for sorting a custom indexed collection. Implement Len, Less, and Swap; then use Sort, Stable, or other sort package functions.

Last updated

Syntax

type Interface interface { Len() int; Less(i, j int) bool; Swap(i, j int) }

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • Sort
  • Stable
  • IsSorted
  • Reverse
  • IntSlice
  • Float64Slice
  • StringSlice

Source: The Go Programming Language Help us shape the future of Go! Take the 2026 Go Developer Survey Source file src / sort / sort.go. Checked 2026-11-03.