Documentation
¶
Overview ¶
Package array provides a generic array implementation in Go.
Index ¶
- func Reduce[T interface{}, K any](a Array[T], cb func(pV K, cV T, index int) K, initial K) K
- type Array
- func (a Array[T]) Filter(cb func(value T, index int) bool) Array[T]
- func (a Array[T]) Find(findFunc func(item T, index int) bool) (T, int)
- func (a Array[T]) FindIndex(findFunc func(item T, index int) bool) int
- func (a Array[T]) FindLast(findFunc func(item T, index int) bool) (T, int)
- func (a Array[T]) ForEach(cb func(value T, index int))
- func (a Array[T]) Go() []T
- func (a *Array[T]) Pop() T
- func (a *Array[T]) Push(arr ...T) int
- func (a *Array[T]) Sort(compareFn ...sortParams[T])
- func (a *Array[T]) Splice(index int, count int) Array[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Array ¶
type Array[T interface{}] []T
Array is a generic data structure that can hold elements of any type.
func Map ¶ added in v1.0.8
Map iterates over the array and calls the callback function for each element. The callback function is passed the value and index of the element. It returns a new Array containing the elements returned by the callback function.
func New ¶
func New[T interface{}](arr ...T) Array[T]
New creates a new Array[T] from a variadic number of arguments. It accepts zero or more arguments of any type and returns an Array containing these elements.
func (Array[T]) Filter ¶ added in v1.0.8
Filter iterates over the array and calls the callback function for each element. The callback function is passed the value and index of the element. It returns a new Array containing the elements for which the callback function returned true.
func (Array[T]) FindIndex ¶ added in v1.0.9
FindIndex returns the index of the first element in the array that satisfies the provided testing function.
func (Array[T]) FindLast ¶ added in v1.0.9
FindLast returns the last element along with index in the array that satisfies the provided testing function.
func (Array[T]) ForEach ¶ added in v1.0.8
ForEach iterates over the array and calls the callback function for each element. The callback function is passed the value and index of the element.
func (Array[T]) Go ¶ added in v1.0.8
func (a Array[T]) Go() []T
Go returns the underlying slice of the array.
func (*Array[T]) Pop ¶
func (a *Array[T]) Pop() T
Pop removes the last element from the array and returns it. If the array is empty, it panics with the message "Array is empty". It returns the removed element.
func (*Array[T]) Push ¶
Push adds a variadic number of arguments to the end of the array. It accepts zero or more arguments of any type and appends them to the end of the array. It returns the new length of the array.
func (*Array[T]) Sort ¶
func (a *Array[T]) Sort(compareFn ...sortParams[T])
compareFn is an optional parameter. only one argument is needed