helpy

package module
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: Apache-2.0 Imports: 0 Imported by: 0

README

go-helpy

GoDoc

go-helpy is a dependency free collection of helper functions that I got tired of reimplementing.

It contains (simple) implementations of:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs[T Number](v T) T

func DerefOrValue

func DerefOrValue[T any](v *T, defaultVal T) *T

DerefOrValue returns v if it is not nil, otherwise returns a pointer to defaultVal.

func Max

func Max[T ComparableNumber](v T, vs ...T) T

Max returns the largest value among v and vs.

func Min

func Min[T ComparableNumber](v T, vs ...T) T

Min returns the smallest element among v and vs.

func Pointer

func Pointer[T any](v T) *T

Pointer returns a pointer to v.

func ValueOrDefault

func ValueOrDefault[T comparable](v T, defaultVal T) T

ValueOrDefault returns v if it isn't the default value of T, and otherwise returns defaultVal.

Types

type ComparableNumber

type ComparableNumber interface {
	~int8 | ~int16 | ~int32 | ~int | ~int64 | ~uint8 | ~uint16 | ~uint32 | ~uint | ~uint64 | ~uintptr
}

type Number

type Number interface {
	ComparableNumber | float32 | float64
}

type Set

type Set[T comparable] map[T]struct{}

func MakeSet

func MakeSet[T comparable](vs ...T) Set[T]

MakeSet returns a lookup map for T

func ToSet

func ToSet[T comparable](vs []T) Set[T]

ToSet returns a lookup map for T.

func (*Set[T]) Add

func (s *Set[T]) Add(v T)

Add adds v to its elements

func (Set[T]) Contains

func (s Set[T]) Contains(v T) bool

Contains returns true if Set contains v.

func (Set[T]) Equal

func (s Set[T]) Equal(s2 Set[T]) bool

Equal returns true if s and s2 are of equal length and all elements contained in one set are contained in the other.

func (Set[T]) Intersect

func (s Set[T]) Intersect(s2 Set[T]) Set[T]

Intersect returns the intersection of two Sets.

func (Set[T]) Subtract

func (s Set[T]) Subtract(s2 Set[T]) Set[T]

Subtract returns a new Set containing all values from s that are not in s2.

func (Set[T]) Union

func (s Set[T]) Union(s2 Set[T]) Set[T]

Union returns the union of two Sets.

Jump to

Keyboard shortcuts

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