Documentation ¶
Index ¶
- func Abs[T constraints.Integer | constraints.Float](val T) T
- func GenerateUniqueAlias() string
- func GetMapKeys[K comparable, V any](m map[K]V) []K
- func GetMapKeysSorted[K cmp.Ordered, V any](m map[K]V) []K
- func GetMapKeysSortedDescending[K cmp.Ordered, V any](m map[K]V) []K
- func GetMapValues[K comparable, V any](m map[K]V) []V
- func IsGeneratedAlias(alias string) bool
- func Max[T constraints.Ordered](vals ...T) (maximum T)
- func Min[T constraints.Ordered](vals ...T) (minimum T)
- func SliceToMapKeys[T comparable](slice []T) map[T]struct{}
- func SliceToMapValues[K comparable, V any](slice []V, getKey func(V) K) map[K]V
- type Stack
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Abs ¶ added in v0.4.0
func Abs[T constraints.Integer | constraints.Float](val T) T
Abs returns the absolute value of the given number.
func GenerateUniqueAlias ¶ added in v0.2.0
func GenerateUniqueAlias() string
GenerateUniqueAlias generates a unique alias. This is thread-safe.
func GetMapKeys ¶ added in v0.2.0
func GetMapKeys[K comparable, V any](m map[K]V) []K
GetMapKeys returns the map's keys as an unsorted slice.
func GetMapKeysSorted ¶ added in v0.2.0
GetMapKeysSorted returns the map's keys as a sorted slice. The keys are sorted in ascending order. For descending order, use GetMapKeysSortedDescending.
func GetMapKeysSortedDescending ¶ added in v0.2.0
GetMapKeysSortedDescending returns the map's keys as a sorted slice. The keys are sorted in descending order. For ascending order, use GetMapKeysSorted.
func GetMapValues ¶ added in v0.2.0
func GetMapValues[K comparable, V any](m map[K]V) []V
GetMapValues returns the map's values as a slice. Due to Go's map iteration, the values will be in a non-deterministic order.
func IsGeneratedAlias ¶ added in v0.2.0
IsGeneratedAlias returns whether the given alias was generated using GenerateUniqueAlias.
func Max ¶ added in v0.4.0
func Max[T constraints.Ordered](vals ...T) (maximum T)
Max returns the largest value of the given parameters. If no parameters are given, then returns the default value for the type.
func Min ¶ added in v0.4.0
func Min[T constraints.Ordered](vals ...T) (minimum T)
Min returns the smallest value of the given parameters.
func SliceToMapKeys ¶ added in v0.2.0
func SliceToMapKeys[T comparable](slice []T) map[T]struct{}
SliceToMapKeys converts the given slice into a map where all of the keys are represented by all of the slice's values.
func SliceToMapValues ¶ added in v0.2.0
func SliceToMapValues[K comparable, V any](slice []V, getKey func(V) K) map[K]V
SliceToMapValues converts the given slice into a map where all of the slice's values are keyed by the output of the `getKey` function, which takes a value and returns a key. It is up to the caller to return a unique key.
Types ¶
type Stack ¶
type Stack[T any] struct { // contains filtered or unexported fields }
Stack is a generic stack.
func (*Stack[T]) Peek ¶
func (s *Stack[T]) Peek() (value T)
Peek returns the top value on the stack without removing it.
func (*Stack[T]) PeekDepth ¶
PeekDepth returns the n-th value from the top. PeekDepth(0) is equivalent to the standard Peek().
func (*Stack[T]) PeekReference ¶
func (s *Stack[T]) PeekReference() *T
PeekReference returns a reference to the top value on the stack without removing it.