util

package
v1.20.1 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

util contains small standalone utility functions. This should have no dependencies on other server packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloneMapNonNil added in v1.18.4

func CloneMapNonNil[M ~map[K]V, K comparable, V any](m M) M

CloneMapNonNil is like maps.Clone except it can't return nil, it will return an empty map instead.

func InverseMap added in v1.20.0

func InverseMap[M ~map[K]V, K, V comparable](m M) map[V]K

InverseMap creates the inverse map, ie., for a key-value map, it builds the value-key map.

func Max

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

Min returns the maximum of two comparable values.

func MaxTime

func MaxTime(a, b time.Time) time.Time

MinTime returns the later of two given time.Time

func Min

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

Min returns the minimum of two comparable values.

func MinTime

func MinTime(a, b time.Time) time.Time

MinTime returns the earlier of two given time.Time

func SliceHead

func SliceHead[S ~[]E, E any](s S, n int) S

SliceHead returns the first n elements of s. n may be greater than len(s).

func SliceTail

func SliceTail[S ~[]E, E any](s S, n int) S

SliceTail returns the last n elements of s. n may be greater than len(s).

func SortSlice

func SortSlice[S ~[]E, E constraints.Ordered](slice S)

SortSlice sorts the given slice of an ordered type. Sort is not guaranteed to be stable.

Types

This section is empty.

Jump to

Keyboard shortcuts

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