utils

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: MIT Imports: 1 Imported by: 1

Documentation

Index

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

func ChunkSlice[T any](s []T, chunkSize int) [][]T

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

func IndexInSlice[T any](v []T, index int) bool

IndexInSlice returns whether an index exists within a given slice

func InsertInSlice added in v0.0.17

func InsertInSlice[T any](in []T, valueToAdd T, index int) []T

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

func MoveInSlice[T any](in []T, oldPosition, newPosition int) []T

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

func RemoveFromSlice[T any](in []T, index int) []T

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

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

SliceFilter calls testFunc on every item given in input, and only returns those that return true.

func SliceFind added in v0.0.15

func SliceFind[T any](input []T, testFunc func(T) bool) (item T, ok bool)

SliceFilter calls testFunc on every item given in input, and returns the first item that returns true

func SliceMap

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

SliceMap takes a slice, calls the func given for every item, then returns a new slice of the transformed value.

func Ternary

func Ternary[T any](exp bool, ifCond T, elseCond T) T

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

func ValueAtIndex[T any](v []T, index int) (T, bool)

ValueAtIndex returns the value at a given index in a slice

Types

This section is empty.

Jump to

Keyboard shortcuts

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