etc

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy[S ~[]E, E any](source S, more ...E) S

creates a copy of the incoming slice, optionally with additional items appended

func InsertAt

func InsertAt[S ~[]E, E any](slice S, index int, value E) S

inserts the given item at the specified index (negative indexes are from the end of the slice) note: reuses the caller's slice when possible (does not guarantee a copy) warn: panics if you are OOB

func InsertRunAt

func InsertRunAt[S ~[]E, E any](slice S, index, count int) S

inserts a series of copies of the specified element at index warn: if index is out of range, go will panic

func InsertSliceAt

func InsertSliceAt[S ~[]E, E any](slice S, subslice S, index int) S

inserts a series of copies of the specified element at index warn: if index is out of range, will panic

func IsOneOf

func IsOneOf[E comparable](v E, slice ...E) bool

returns true if the given value is in the slice (handy for inline checks)

func Keys

func Keys[K comparable, V any](m map[K]V) (results []K)

returns the keys from a map (in unpredictable order)

func MakeRun

func MakeRun[S ~[]E, E any](element E, count int) S

returns a slice that is a simple run of the given element warn: if count is negative, go will panic

func MulDiv

func MulDiv[T constraints.Integer](value, numerator, denominator T) T

multiply two numbers and divide by a third of the same type (often useful for constraints.Integereger math)

func MulDivRoundUp

func MulDivRoundUp[T constraints.Integer](value, numerator, denominator T) T

multiply two numbers and divide by a third of the same type, rounding up

func RemoveSpan

func RemoveSpan[S ~[]E, E any](slice S, startIndex, count int) S

creates a new slice sans the given sub-span

func RemoveSpanInSitu

func RemoveSpanInSitu[S ~[]E, E any](slice S, startIndex, count int) S

removes the specified subset from the span (overwrites the slice memory)

func Reverse

func Reverse[S ~[]E, E any](s S) S

returns the reverse of the input slice (the output is separate from the input)

func ReverseInSitu

func ReverseInSitu[S ~[]E, E any](s S) S

does an in-situ reversal of any slice

func SortedKeys

func SortedKeys[K ~string, V any](m map[K]V) (results []K)

returns the keys from a map (in sorted order)

Types

This section is empty.

Jump to

Keyboard shortcuts

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