Documentation
¶
Index ¶
- func AnyWithin[V comparable, S ~[]V](src S, others ...S) (present bool)
- func Append[V comparable, S ~[]V](src S, values ...V) (modified S)
- func Carve[V comparable, S ~[]V](src, start, end S) (before, middle, after S, found bool)
- func CarveString[V ~string](src, start, end V) (before, middle, after V, found bool)
- func Copy[V interface{}, S ~[]V](slice S) (copied S)
- func Cut[V comparable, S ~[]V](src, sep S) (before, after S, found bool)
- func DuplicateCounts[V comparable, S ~[]V](src S) (counts map[V]int)
- func Equal[V comparable, S ~[]V](src S, others ...S) (same bool)
- func IndexOf[V comparable, S ~[]V](slice S, value V) (index int)
- func IndexesOf[V comparable, S ~[]V](slice S, value V) (indexes []int)
- func Insert[V interface{}, S ~[]V](slice S, at int, values ...V) (modified S)
- func MakeLookup[V comparable](slices ...[]V) (lookup map[V]struct{})
- func Merge[V comparable, S ~[]V](src S, others ...S) (modified S)
- func Pop[V interface{}, S ~[]V](slice S) (modified S, value V)
- func Present[V comparable](search V, others ...V) (present bool)
- func Prune[V comparable, S ~[]V](slice S, values ...V) (modified S)
- func Push[V interface{}, S ~[]V](slice S, values ...V) (modified S)
- func Remove[V interface{}, S ~[]V](slice S, at int) (modified S)
- func Retype[T interface{}](src []interface{}) (slice []T, ok bool)
- func Shift[V interface{}, S ~[]V](slice S, values ...V) (modified S)
- func StartsWith[V comparable, S ~[]V](src S, others ...S) (same bool)
- func ToCamels(list []string) (camel []string)
- func ToKebabs(list []string) (kebabs []string)
- func ToScreamingKebabs(list []string) (screamingKebabs []string)
- func ToScreamingSnakes(list []string) (screamingSnakes []string)
- func ToSnakes(list []string) (snakes []string)
- func ToStrings[V interface{}](slice []V) (values []string)
- func Truncate[V interface{}, S ~[]V](slice S, length int) (truncated S)
- func Unique[V comparable, S ~[]V](src S) (unique S)
- func Unshift[V interface{}, S ~[]V](slice S) (modified S, value V)
- func Within[V comparable, S ~[]V](search V, others ...S) (present bool)
- type Stack
- func (s *Stack[V]) First() (item V, ok bool)
- func (s *Stack[V]) Get(idx int) (item V, ok bool)
- func (s *Stack[V]) Last() (item V, ok bool)
- func (s *Stack[V]) Len() (size int)
- func (s *Stack[V]) Pop() (item V, ok bool)
- func (s *Stack[V]) Push(item V)
- func (s *Stack[V]) Set(idx int, item V) (ok bool)
- func (s *Stack[V]) Shift(item V)
- func (s *Stack[V]) Slice() (items []V)
- func (s *Stack[V]) Unshift() (item V, ok bool)
- func (s *Stack[V]) Valid(idx int) (valid bool)
- type StackComparable
- type StackUnique
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnyWithin ¶
func AnyWithin[V comparable, S ~[]V](src S, others ...S) (present bool)
AnyWithin returns true if any of the values in the source given are present in any of the other slices given
func Append ¶
func Append[V comparable, S ~[]V](src S, values ...V) (modified S)
Append returns a new slice appended with only values not within the src slice
func Carve ¶ added in v1.2.0
func Carve[V comparable, S ~[]V](src, start, end S) (before, middle, after S, found bool)
Carve finds the `start` and `end` markers in `src` and carves out the "before carve", "middle of start/end range" and "after carve" segments. If the `start` and `end` range is not `found` then the `before` will contain the entire `src` input
func CarveString ¶ added in v1.3.0
CarveString recasts the given ~string arguments to []rune slices, calls Carve and recasts the []rune slices returns values back to the original type
func Copy ¶
func Copy[V interface{}, S ~[]V](slice S) (copied S)
Copy creates a new slice (array) from the given slice
func Cut ¶ added in v1.1.0
func Cut[V comparable, S ~[]V](src, sep S) (before, after S, found bool)
Cut is the slices version of strings.Cut
func DuplicateCounts ¶
func DuplicateCounts[V comparable, S ~[]V](src S) (counts map[V]int)
DuplicateCounts returns a mapping of values and their respective counts, distinct values not included
func Equal ¶
func Equal[V comparable, S ~[]V](src S, others ...S) (same bool)
Equal returns true if all the slices given have the same values
func IndexOf ¶
func IndexOf[V comparable, S ~[]V](slice S, value V) (index int)
IndexOf returns the first index matching the value given
func IndexesOf ¶
func IndexesOf[V comparable, S ~[]V](slice S, value V) (indexes []int)
IndexesOf returns a list of all indexes matching the value given
func Insert ¶
func Insert[V interface{}, S ~[]V](slice S, at int, values ...V) (modified S)
Insert creates a new slice (array) from the given slice, with additional values inserted at the given index
func MakeLookup ¶ added in v1.6.0
func MakeLookup[V comparable](slices ...[]V) (lookup map[V]struct{})
MakeLookup creates a mapping of generic comparable slices with empty structs
func Merge ¶
func Merge[V comparable, S ~[]V](src S, others ...S) (modified S)
Merge returns a new slice with the new values found within others appended to the src slice
func Pop ¶
func Pop[V interface{}, S ~[]V](slice S) (modified S, value V)
Pop removes the last value from a Copy of the slice and returns it
func Present ¶
func Present[V comparable](search V, others ...V) (present bool)
Present returns true if the search value is present in any of the other values given
func Prune ¶
func Prune[V comparable, S ~[]V](slice S, values ...V) (modified S)
Prune removes all instances of the specified values from a copy of the given slice
func Push ¶
func Push[V interface{}, S ~[]V](slice S, values ...V) (modified S)
Push appends the given value to a new copy of the given slice
func Remove ¶
func Remove[V interface{}, S ~[]V](slice S, at int) (modified S)
Remove creates a new slice (array) from the given slice, with the specified index removed
func Shift ¶
func Shift[V interface{}, S ~[]V](slice S, values ...V) (modified S)
Shift prepends the given value to a new copy of the given slice
func StartsWith ¶
func StartsWith[V comparable, S ~[]V](src S, others ...S) (same bool)
StartsWith returns true if the other slices given start with the same values as the src
func ToScreamingKebabs ¶
func ToScreamingSnakes ¶
func ToStrings ¶ added in v1.6.0
func ToStrings[V interface{}](slice []V) (values []string)
ToStrings creates a new string slice with all the given slice's values, converted to strings using fmt.Sprintf("%v", value) unless the value is of type rune, string, []byte or []rune, in which case they're simply recast as string
func Truncate ¶
func Truncate[V interface{}, S ~[]V](slice S, length int) (truncated S)
Truncate creates a new slice (array), of specified length, from the given slice
func Unique ¶
func Unique[V comparable, S ~[]V](src S) (unique S)
Unique returns a new slice with duplicate values omitted, maintaining order
func Unshift ¶
func Unshift[V interface{}, S ~[]V](slice S) (modified S, value V)
Unshift removes the first value from a Copy of the slice and returns it
func Within ¶
func Within[V comparable, S ~[]V](search V, others ...S) (present bool)
Within return true if the search value is present in any of the other slices of V given
Types ¶
type Stack ¶ added in v1.5.0
Stack is a concurrency-safe manager for a stack of generic items
func NewStack ¶ added in v1.5.0
func NewStack[V interface{}](items ...V) *Stack[V]
NewStack creates a new Stack instance
func (*Stack[V]) Push ¶ added in v1.5.0
func (s *Stack[V]) Push(item V)
Push appends the given item to the end of the Stack
func (*Stack[V]) Shift ¶ added in v1.5.0
func (s *Stack[V]) Shift(item V)
Shift prepends the given item to the start of the Stack
func (*Stack[V]) Slice ¶ added in v1.6.0
func (s *Stack[V]) Slice() (items []V)
Slice returns the stack as a slice
type StackComparable ¶ added in v1.6.0
type StackComparable[V comparable] struct { Stack[V] }
StackComparable is a concurrency-safe manager for a stack of generic comparable items
func NewStackComparable ¶ added in v1.6.0
func NewStackComparable[V comparable](items ...V) *StackComparable[V]
NewStackComparable creates a new StackComparable instance
func (*StackComparable[V]) Find ¶ added in v1.6.0
func (s *StackComparable[V]) Find(search V) (index int, ok bool)
Find searches the stack for the first instance of the search value
func (*StackComparable[V]) Has ¶ added in v1.6.0
func (s *StackComparable[V]) Has(search V) (ok bool)
Has returns true if this stack has the search value
func (*StackComparable[V]) Prune ¶ added in v1.6.0
func (s *StackComparable[V]) Prune(search ...V) (count int)
Prune removes the search values from the stack, returns the number of items removed
type StackUnique ¶ added in v1.6.0
type StackUnique[V comparable] struct { StackComparable[V] }
StackUnique is a concurrency-safe manager for a stack of unique generic comparable items
func NewStackUnique ¶ added in v1.6.0
func NewStackUnique[V comparable](items ...V) *StackUnique[V]
NewStackUnique creates a new StackUnique instance
func (*StackUnique[V]) Push ¶ added in v1.6.0
func (s *StackUnique[V]) Push(item V)
Push appends the given item to the end of the Stack
func (*StackUnique[V]) Set ¶ added in v1.6.0
func (s *StackUnique[V]) Set(idx int, item V) (ok bool)
Set overwrites the item at the index given
func (*StackUnique[V]) Shift ¶ added in v1.6.0
func (s *StackUnique[V]) Shift(item V)
Shift prepends the given item to the start of the Stack