Documentation
¶
Index ¶
- func AnyValueInMap[T comparable, V any](m map[T]V, values ...T) bool
- func ChunkSlice[T any](s []T, chunkSize int) [][]T
- func FirstOf[T any](v []T) T
- func IndexInSlice[T any](v []T, index int) bool
- func InsertInSlice[T any](in []T, valueToAdd T, index int) []T
- func InvertMap[K comparable, V comparable](m map[K]V) map[V]K
- func MapKeys[K comparable, V any](v map[K]V) []K
- func MapValues[K comparable, V any](in map[K]V) []V
- func MoveInSlice[T any](in []T, oldPosition, newPosition int) []T
- func RemoveFromSlice[T any](in []T, index int) []T
- func ReverseSlice[T any](s []T)
- func SliceFilter[T any](input []T, testFunc func(T) bool) []T
- func SliceFind[T any](input []T, testFunc func(T) bool) (item T, ok bool)
- func SliceMap[T any, R any](input []T, mapFunc func(T) R) []R
- func Ternary[T any](exp bool, ifCond T, elseCond T) T
- func UniqueSlice[T comparable](input []T) []T
- func ValueAtIndex[T any](v []T, index int) (T, bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnyValueInMap ¶ added in v0.0.5
func AnyValueInMap[T comparable, V any](m map[T]V, values ...T) bool
AnyValueInMap iterates through values and returns true if any has a key in the map.
func ChunkSlice ¶ added in v0.0.16
ChunkSlice splits a slice into chunks of a given size.
func FirstOf ¶ added in v0.0.8
func FirstOf[T any](v []T) T
FirstOf returns the first item in a slice
func IndexInSlice ¶ added in v0.0.11
IndexInSlice returns whether an index exists within a given slice
func InsertInSlice ¶ added in v0.0.17
InsertInSlice inserts a value into a slice at a given position
If the position gives is out of bounds then it resorts to inserting to the end of the slice
func InvertMap ¶ added in v0.0.7
func InvertMap[K comparable, V comparable](m map[K]V) map[V]K
InvertMap inverts the map keys and values
func MapKeys ¶ added in v0.0.14
func MapKeys[K comparable, V any](v map[K]V) []K
MapKeys returns all keys in a given map, **the order will not be stable, you should sort these values if needed.**
func MapValues ¶ added in v0.0.14
func MapValues[K comparable, V any](in map[K]V) []V
MapValues returns all values in a given map, **the order is not stable, you should sort it if you need a stable order.**
func MoveInSlice ¶ added in v0.0.17
MoveInSlice moves a value within the slice to a specified new position
If either the old or new position is out of bounds, the existing slice contents is returned.
func RemoveFromSlice ¶ added in v0.0.17
RemoveFromSlice removes a value from slice at a given index
func ReverseSlice ¶
func ReverseSlice[T any](s []T)
ReverseSlice reverses all slice elements in place. Note: this will mutate your given slice.
func SliceFilter ¶
SliceFilter calls testFunc on every item given in input, and only returns those that return true.
func SliceFind ¶ added in v0.0.15
SliceFilter calls testFunc on every item given in input, and returns the first item that returns true
func SliceMap ¶
SliceMap takes a slice, calls the func given for every item, then returns a new slice of the transformed value.
func Ternary ¶
Ternary allows you to write ternary expressions in go, if exp is true, then ifCond is returned, else, elseCond is returned.
func UniqueSlice ¶ added in v0.0.4
func UniqueSlice[T comparable](input []T) []T
UniqueSlice is a helper function that iterates through your slice and returns a copy with only the unique values.
func ValueAtIndex ¶ added in v0.0.11
ValueAtIndex returns the value at a given index in a slice
Types ¶
This section is empty.