utils

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package utils contains various util functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MapGetKeyAsType

func MapGetKeyAsType[T any](key string, m map[string]any) (T, error)

MapGetKeyAsType retrieves a key from a map and converts it to a given type

func MapValues

func MapValues[T comparable, U any](input map[T]U) []U

MapValues returns a slice of all values

func SliceDereference

func SliceDereference[T any](input []*T) []T

SliceDereference converts a []*T slice to []T

func SliceFilter

func SliceFilter[T any](input []T, filter func(T) bool) []T

SliceFilter returns a new slice consisting of elements that passed the filter function

func SliceFind

func SliceFind[T any](input []T, equal func(T) bool) (*T, bool)

SliceFind returns a pointer to the first item determined by the equal function, nil if not found The second argument returns true if found, false otherwise

func SliceFlatten

func SliceFlatten[T any](slice [][]T) []T

SliceFlatten flattens 2D slices to 1D

func SliceMap

func SliceMap[T any, U any](input []T, mapFunc func(T) U) []U

SliceMap maps a slice of type T to a slice of type U

func SliceMerge

func SliceMerge[T any](slices ...[]T) []T

SliceMerge merges multiple slices together

func SliceReference

func SliceReference[T any](input []T) []*T

SliceReference converts a []T slice to []*T

func SliceRepeat

func SliceRepeat[T any](value T, count int) []T

SliceRepeat constructs a slice of length `count` of element `value`

func SliceSanitize

func SliceSanitize[T comparable](slice []T) []T

SliceSanitize removes all null values according to T{}

func SliceToMap

func SliceToMap[T any, U comparable](input []T, toKey func(T) U) map[U]T

SliceToMap maps a slice to a map with key -> result of toKey function value -> slice entry

func SliceUnique

func SliceUnique[T comparable](input []T) []T

SliceUnique filters out all duplicate elements

func SliceUniqueFunc

func SliceUniqueFunc[T any, U comparable](input []T, unique func(t T) U) []T

SliceUniqueFunc filters out all duplicate elements The unique function should return an comparable that is unique for unique elements

Types

This section is empty.

Jump to

Keyboard shortcuts

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