utils

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chunk

func Chunk[T any](slice []T, chunkSize int) [][]T

func Contains

func Contains[T Ordered](slice *[]T, v T) bool

func GetOrDefault

func GetOrDefault(s *string, defaultValue string) string

GetOrDefault returns the value of the given string pointer if it is not nil, otherwise it returns the provided default value.

func HashMap

func HashMap[T any](slice *[]T, keyField string) (map[interface{}]T, error)

HashMap creates a map using the specified key field from the elements of the given slice. The key field must be a valid field name in the struct elements of the slice. The function returns the created map and an error, if any.

func Percent

func Percent[T Numbers, E Numbers](percent T, all E) float64

func PercentOf

func PercentOf[T Numbers, E Numbers](part T, total E) float64

func ResizeImage

func ResizeImage(image image.Image, width, height int) image.Image

Types

type Float

type Float interface {
	~float32 | ~float64
}

type Integer

type Integer interface {
	Signed | Unsigned
}

type Numbers

type Numbers interface {
	Signed | Unsigned | Float
}

type Ordered

type Ordered interface {
	Integer | Float | ~string
}

type Signed

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

Jump to

Keyboard shortcuts

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