utils

package
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: BSD-2-Clause, ISC Imports: 4 Imported by: 3

Documentation

Overview

Package utils provides common utility functions.

Provided functionalities: - sorting - comparators

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteComparator

func ByteComparator(a, b byte) int

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

func RuneComparator(a, b rune) int

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

func StringComparator(a, b string) int

StringComparator provides a fast comparison on strings

func TimeComparator

func TimeComparator(a, b time.Time) int

TimeComparator provides a basic comparison on time.Time

func ToString

func ToString(value interface{}) string

ToString converts a value to string.

Types

type ComparableNumber added in v0.4.0

type ComparableNumber interface {
	int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | float32 | float64
}

type Comparator

type Comparator[T comparable] func(a, b T) int

Jump to

Keyboard shortcuts

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