xsort

package module
v0.0.0-...-f6cb7f6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Asc

func Asc[T constraints.Ordered](slices []T)

func Desc

func Desc[T constraints.Ordered](slices []T)

func SortableAsc

func SortableAsc[T Sortable[T]](slices []T)

SortableAsc is a function that takes in a slice of type T and sorts it in ascending order. The type T must implement the Sortable interface, which requires the Less() method to be defined. The function uses the sort.Slice() method from the sort package to sort the slice, using a comparison function that compares two elements of the slice using their Less() methods.

func SortableDesc

func SortableDesc[T Sortable[T]](slices []T)

SortableDesc is a function that takes in a slice of type T, where T is a type that implements the Sortable interface. The function sorts the slice in descending order using the Less method from the Sortable interface.

Types

type Sortable

type Sortable[T any] interface {
	Less(other T) bool
}

Sortable[T any] is an interface that defines a type T and a function Less that takes another type T as an argument and returns a boolean. The Less function is used to compare two values of type T and determine which one is "less" than the other.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL