Documentation ¶
Overview ¶
Package utils provides common utility functions.
Provided functionalities: - sorting - comparators
Index ¶
- func ByteComparator(a, b byte) int
- func GenericToInterfaceSlice[T any](t []T) []interface{}
- func NumberComparator[T ComparableNumber](a, b T) int
- func RuneComparator(a, b rune) int
- func Sort[T comparable](values []T, comparator Comparator[T])
- func StringComparator(a, b string) int
- func TimeComparator(a, b time.Time) int
- func ToString(value interface{}) string
- type ComparableNumber
- type Comparator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ByteComparator ¶
ByteComparator provides a basic comparison on byte
func GenericToInterfaceSlice ¶ added in v0.6.0
func GenericToInterfaceSlice[T any](t []T) []interface{}
func NumberComparator ¶ added in v0.4.0
func NumberComparator[T ComparableNumber](a, b T) int
NumberComparator provides a basic comparison on int
func RuneComparator ¶
RuneComparator provides a basic comparison on rune
func Sort ¶
func Sort[T comparable](values []T, comparator Comparator[T])
Sort sorts values (in-place) with respect to the given comparator.
Uses Go's sort (hybrid of quicksort for large and then insertion sort for smaller slices).
func StringComparator ¶
StringComparator provides a fast comparison on strings
func TimeComparator ¶
TimeComparator provides a basic comparison on time.Time
Types ¶
type ComparableNumber ¶ added in v0.4.0
type Comparator ¶
type Comparator[T comparable] func(a, b T) int
Click to show internal directories.
Click to hide internal directories.