utils

package
v0.23.1 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2022 License: BSD-2-Clause, ISC Imports: 5 Imported by: 2

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 BasicComparator added in v0.3.0

func BasicComparator[T constraints.Ordered](a, b T) int

func Max added in v0.16.0

func Max[T constraints.Ordered](a T, b T) T

func Min added in v0.16.0

func Min[T constraints.Ordered](a T, b T) T

func Sort

func Sort[T any](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 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 Comparator

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

Comparator will make type assertion (see IntComparator for example), which will panic if a or b are not of the asserted type.

Should return a number:

negative , if a < b
zero     , if a == b
positive , if a > b

Jump to

Keyboard shortcuts

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