Documentation
¶
Overview ¶
Package array provides functions for manipulating golang slices.
Index ¶
- func At[T comparable](slice []T, index int) (T, error)
- func Concat[T comparable](slice1 []T, slice2 ...[]T) []T
- func ConvertIndex[T comparable](slice []T, index int, nameOfIndex string) (int, error)
- func CopyWithin[T comparable](slice []T, target int, start int, end int) ([]T, error)
- func Every[T comparable](slice []T, fn Predicate[T]) bool
- func Fill[T comparable](slice []T, value T, start int, end int) ([]T, error)
- func Filter[T comparable](slice []T, fn Predicate[T]) []T
- func Find[T comparable](slice []T, fn Predicate[T]) *T
- func FindIndex[T comparable](slice []T, fn Predicate[T]) int
- func FindLast[T comparable](slice []T, fn Predicate[T]) *T
- func FindLastIndex[T comparable](slice []T, fn Predicate[T]) int
- func ForEach[T comparable](slice []T, fn ForEachFunc[T])
- func Includes[T comparable](slice []T, element T, start *int) bool
- func IndexOf[T comparable](slice []T, element T, start *int) int
- func Join(slice []string, separator *string) string
- func LastIndexOf[T comparable](slice []T, element T, start *int) int
- func Map[T comparable](slice []T, fn MapFunc[T]) []any
- func MapStrict[T comparable](slice []T, fn MapFuncStrict[T]) []T
- func Pop[T comparable](slice []T) ([]T, *T)
- func Push[T comparable](slice []T, elements ...T) []T
- func Reduce[T comparable](slice []T, fn ReduceFunc[T], initialValue any) (any, error)
- func ReduceRight[T comparable](slice []T, fn ReduceFunc[T], initialValue any) (any, error)
- func ReduceRightStrict[T comparable](slice []T, fn ReduceStrictFunc[T], initialValue *T) (T, error)
- func ReduceStrict[T comparable](slice []T, fn ReduceStrictFunc[T], initialValue *T) (T, error)
- func Reverse[T comparable](slice []T) []T
- func Shift[T comparable](slice []T) ([]T, *T)
- func Slice[T comparable](slice []T, start, end int) ([]T, error)
- func Some[T comparable](slice []T, fn Predicate[T]) bool
- func Splice[T comparable](slice []T, index int, howMany *int, elements ...T) ([]T, error)
- func ToString(slice []string) string
- func UnShift[T comparable](slice []T, element ...T) []T
- func ValueOf[T comparable](slice []T) []T
- func With[T comparable](slice []T, index int, value T) ([]T, error)
- type Entry
- type ForEachFunc
- type MapFunc
- type MapFuncStrict
- type Predicate
- type ReduceFunc
- type ReduceStrictFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func At ¶
func At[T comparable](slice []T, index int) (T, error)
The At() function returns an indexed element from a slice and returns a possible error relating to out of range indexes.
func Concat ¶
func Concat[T comparable](slice1 []T, slice2 ...[]T) []T
The concat() function concatenates (joins) two or more slices. The concat() function returns a new slice, containing the joined slices. The concat() function does not change the existing slices.
func ConvertIndex ¶ added in v0.0.5
func ConvertIndex[T comparable](slice []T, index int, nameOfIndex string) (int, error)
func CopyWithin ¶ added in v0.0.5
func CopyWithin[T comparable](slice []T, target int, start int, end int) ([]T, error)
The CopyWithin() function returns a copy of slice elements to another position in an slice and a possible error relating to out of range indexes.. The CopyWithin() function overwrites the existing values in the new slice.
func Every ¶
func Every[T comparable](slice []T, fn Predicate[T]) bool
The Every() function executes a function for each slice element. The Every() function returns true if the function returns true for all elements. The Every() function returns false if the function returns false for one element. The Every() function does not execute the function for empty elements. The Every() function does not change the original slice.
func Fill ¶
func Fill[T comparable](slice []T, value T, start int, end int) ([]T, error)
The Fill() function returns fills of specified elements in an slice with a value and a possible error due to indexes out of range.
func Filter ¶
func Filter[T comparable](slice []T, fn Predicate[T]) []T
The filter() function creates a new slice filled with elements that pass a test provided by a function. The filter() function does not execute the function for empty elements.
func Find ¶
func Find[T comparable](slice []T, fn Predicate[T]) *T
The Find() function returns a pointer value of the first element that passes a test. The Find() function executes a function for each slice element. The Find() function returns undefined if no elements are found. The Find() function does not execute the function for empty elements. The Find() function does not change the original slice
func FindIndex ¶
func FindIndex[T comparable](slice []T, fn Predicate[T]) int
The FindIndex() function executes a function for each slice element. The FindIndex() function returns the index (position) of the first element that passes a test. The FindIndex() function returns -1 if no match is found. The FindIndex() function does not execute the function for empty slice elements. The FindIndex() function does not change the original slice.
func FindLast ¶
func FindLast[T comparable](slice []T, fn Predicate[T]) *T
The FindLast() function returns the value of the last element that passes a test. The FindLast() function executes a function for each slice element. The FindLast() function returns -1 if no elements are found. The FindLast() function does not execute the function for empty elements. The FindLast() function does not change the original slice.
func FindLastIndex ¶
func FindLastIndex[T comparable](slice []T, fn Predicate[T]) int
func ForEach ¶
func ForEach[T comparable](slice []T, fn ForEachFunc[T])
func Includes ¶
func Includes[T comparable](slice []T, element T, start *int) bool
func IndexOf ¶
func IndexOf[T comparable](slice []T, element T, start *int) int
The IndexOf() function returns the first index (position) of a specified value. The IndexOf() function returns -1 if the value is not found. The IndexOf() function starts at a specified index and searches from left to right (from the given start postion to the end of the array). By default the search starts at the first element and ends at the last. Negative start values counts from the last element (but still searches from left to right).
func Join ¶ added in v0.0.5
The Join() function returns an slice as a string. The Join() function does not change the original slice. Any separator can be specified. The default is comma (,). Join function only works for strings.
func LastIndexOf ¶ added in v0.0.5
func LastIndexOf[T comparable](slice []T, element T, start *int) int
The IndexOf() function returns the first index (position) of a specified value and a possible error due to indexes out of range. The IndexOf() function returns -1 if the value is not found. The IndexOf() function starts at a specified index and searches from left to right (from the given start postion to the end of the array). By default the search starts at the first element and ends at the last. Negative start values counts from the last element (but still searches from left to right).
func Map ¶
func Map[T comparable](slice []T, fn MapFunc[T]) []any
Map() creates a new slice from calling a function for every slice element. Map creates a new slice of any type. Map() does not execute the function for empty elements. Map() does not change the original slice.
func MapStrict ¶ added in v0.0.5
func MapStrict[T comparable](slice []T, fn MapFuncStrict[T]) []T
Map() creates a new slice from calling a function for every slice element. Map creates a new slice of the original slice type. Map() does not execute the function for empty elements. Map() does not change the original slice.
func Pop ¶
func Pop[T comparable](slice []T) ([]T, *T)
The Pop() function removes (pops) the last element of an slice. The Pop() function does not change the original slice. The Pop() function returns the new slice without the last element and a pointer of removed element.
func Push ¶
func Push[T comparable](slice []T, elements ...T) []T
The Push() function adds new items to the end of an slice. The Push() function returns the new slice.
func Reduce ¶
func Reduce[T comparable](slice []T, fn ReduceFunc[T], initialValue any) (any, error)
The Reduce() function executes a Reducer function for slice element. The Reduce() function returns the function's accumulated result and an an error. The Reduce() function does not execute the function for empty slice elements. The Reduce() function does not change the original slice. Note at the first callback, there is no return value from the previous callback. Normally, alice element 0 is used as initial value, and the iteration starts from slice element 1. If an initial value is supplied, this is used, and the iteration starts from slice element 0.
func ReduceRight ¶ added in v0.0.5
func ReduceRight[T comparable](slice []T, fn ReduceFunc[T], initialValue any) (any, error)
The Reduce() function executes a Reducer function for slice element. The ReduceRight() function works from right to left. The Reduce() function returns the function's accumulated result and an an error. The Reduce() function does not execute the function for empty slice elements. The Reduce() function does not change the original slice. Note at the first callback, there is no return value from the previous callback. Normally, alice element 0 is used as initial value, and the iteration starts from slice element 1. If an initial value is supplied, this is used, and the iteration starts from slice element 0.
func ReduceRightStrict ¶ added in v0.0.5
func ReduceRightStrict[T comparable](slice []T, fn ReduceStrictFunc[T], initialValue *T) (T, error)
The ReduceStrict() function executes a Reducer function for slice element. The ReduceRightStrict() function works from right to left . The ReduceStrict() function returns the function's accumulated result(typed with the slices type) and an an error. The ReduceStrict() function does not execute the function for empty slice elements. The ReduceStrict() function does not change the original slice. Note at the first callback, there is no return value from the previous callback. Normally, alice element 0 is used as initial value, and the iteration starts from slice element 1. If an initial value is supplied, this is used, and the iteration starts from slice element 0.
func ReduceStrict ¶
func ReduceStrict[T comparable](slice []T, fn ReduceStrictFunc[T], initialValue *T) (T, error)
The ReduceStrict() function executes a Reducer function for slice element. The ReduceStrict() function returns the function's accumulated result(typed with the slices type) and an an error. The ReduceStrict() function does not execute the function for empty slice elements. The ReduceStrict() function does not change the original slice. Note at the first callback, there is no return value from the previous callback. Normally, alice element 0 is used as initial value, and the iteration starts from slice element 1. If an initial value is supplied, this is used, and the iteration starts from slice element 0.
func Reverse ¶
func Reverse[T comparable](slice []T) []T
The Reverse() function Reverses the order of the elements in an slice. The Reverse() function does not overwrites the original array.
func Shift ¶
func Shift[T comparable](slice []T) ([]T, *T)
The Shift() function removes the first item of an slice. The Shift() function changes the original slice. The Shift() function returns the new slice and a pointer to the shifted element.
func Slice ¶
func Slice[T comparable](slice []T, start, end int) ([]T, error)
The Slice() function returns selected elements in an slice, as a new slice and and error. The Slice() function selects from a given start, up to a (not inclusive) given end. The Slice() function does not change the original slice.
func Some ¶
func Some[T comparable](slice []T, fn Predicate[T]) bool
The Some() function checks if any slice elements pass a test (provided as a callback function). The Some() function executes the callback function once for each slice element.The Some() function returns true (and stops) if the function returns true for one of the slice elements. The Some() function returns false if the function returns false for all of the slice elements. The Some() function does not execute the function for empty slice elements. The Some() function does not change the original slice.
func Splice ¶ added in v1.0.0
func Splice[T comparable](slice []T, index int, howMany *int, elements ...T) ([]T, error)
The Splice() function adds and/or removes slice elements. The Splice() function does not overwrites the original slice.
func ToString ¶ added in v1.0.0
The ToString() function returns a string with slice values separated by commas. The ToString() function does not change the original slice. The ToString function only works for a slice of strings.
func UnShift ¶
func UnShift[T comparable](slice []T, element ...T) []T
The Unshift() function adds new elements to the beginning of an slice. The Unshift() function does not overwrite the original slice.
func ValueOf ¶ added in v0.0.5
func ValueOf[T comparable](slice []T) []T
The ValueOf() function returns the slice itself. The ValueOf() function does not change the original slice. fruits. ValueOf() returns the same as fruits.
func With ¶ added in v0.0.5
func With[T comparable](slice []T, index int, value T) ([]T, error)
The With() function updates a specified slice element. The With() function returns a new slice. The With() function does not change the original slice.
Types ¶
type Entry ¶
type Entry[T comparable] struct { // contains filtered or unexported fields }
func Entries ¶
func Entries[T comparable](slice []T) []Entry[T]
The entries() function returns an Slice with structs with field/value: {index 0, element "Banana"}. The entries() function does not change the original slice.
type ForEachFunc ¶
type ForEachFunc[T comparable] func(element T, index int, slice []T)
type MapFunc ¶
type MapFunc[T comparable] func(element T, index int, slice []T) any
type MapFuncStrict ¶ added in v0.0.5
type MapFuncStrict[T comparable] func(element T, index int, slice []T) T
type Predicate ¶
type Predicate[T comparable] func(element T, index int, slice []T) bool
type ReduceFunc ¶
type ReduceFunc[T comparable] func(total any, currentValue T, currentIndex int, slice []T) any
type ReduceStrictFunc ¶
type ReduceStrictFunc[T comparable] func(total T, currentValue T, currentIndex int, slice []T) T
Source Files
¶
- at.go
- concat.go
- copyWithin.go
- entries.go
- every.go
- fill.go
- filter.go
- find.go
- findIndex.go
- findLast.go
- findLastIndex.go
- flat.go
- forEach.go
- includes.go
- indexOf.go
- join.go
- lastIndexOf.go
- map.go
- pop.go
- push.go
- reduce.go
- reduceRight.go
- reverse.go
- shift.go
- slice.go
- some.go
- splice.go
- toString.go
- types.go
- unshift.go
- utils.go
- valueOf.go
- with.go