Standard library / slices

slices.MinFunc()

Returns the first minimal element under the comparator; panics on empty input. Expected stdout: 'b\n'.

Formal Syntax & Structure

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

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

E

Returns the first minimal element under the comparator; panics on empty input.

Working Example

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