array

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chunk

func Chunk(array interface{}, size int) (interface{}, error)

Chunk divides a given array into smaller chunks of the specified size. The function accepts an array of any type (interface{}) and a size for each Chunk. It returns a Slice of slices, where each inner Slice contains elements from the original array. The Last Chunk may contain fewer elements if the length of the array is not divisible by the Chunk size.

func Concat

func Concat(array, extend interface{}) (interface{}, error)

Concat concatenates two arrays into a single array. The function accepts two arrays of any type (interface{}) and returns a single concatenated array.

func Difference

func Difference(array interface{}, exclude ...interface{}) (interface{}, error)

Difference returns a new Slice that contains the elements from the input array that are not present in the exclude slices. It takes an array-like data structure and one or more exclude slices. The function returns the new Slice of different elements and an error if any occurs.

func Drop

func Drop(array interface{}, num ...int) (interface{}, error)

Drop returns a new array with `n` elements dropped from the beginning. The function accepts an array of any type (interface{}) and an optional number `num` of elements to Drop. It returns a new array with the specified number of elements removed from the beginning.

func DropRight

func DropRight(array interface{}, num ...int) (interface{}, error)

DropRight returns a new array with `num` elements dropped from the end. The function accepts an array of any type (interface{}) and an optional number `num` of elements to Drop. It returns a new array with the specified number of elements removed from the end.

func Fill

func Fill(array, input interface{}, start, end int) (interface{}, error)

Fill elements of an array (Slice) with a specified value within the specified range. The function accepts an array (Slice), a value to Fill with, and optional start and end indices. It returns the modified array with filled values. If the input is not a Slice or if the start or end indices are out of bounds, the function returns an error.

func FindIndex

func FindIndex(array, target interface{}) (int, bool)

FindIndex uses reflection to find the index of the 'target' value in the 'array'. It returns the index of the first occurrence of 'target' and a boolean indicating if the target was found. If 'target' is not found in 'array', the function returns -1 and false.

func Head(array interface{}) interface{}

Head returns the first element of an array (Slice). The function accepts an array (Slice) and returns the first element of the array. If the array is empty or not a Slice, the function returns nil.

func IndexOf

func IndexOf(array, input interface{}, fromIndex ...int) interface{}

IndexOf finds the index of the first occurrence of a value in an array (Slice). The function accepts an array (Slice), a value to search for, and an optional fromIndex. It returns the index of the first occurrence of the value in the array. If the value is not found, the function returns -1.

func Initial

func Initial(array interface{}) (interface{}, error)

Initial returns a new array (Slice) containing all elements of the input array except the Last one. The function accepts an array (Slice) and returns a new array with all elements except the Last one. If the input is not a Slice or if the array is empty, the function returns an error.

func Intersection

func Intersection(array, other interface{}) (interface{}, error)

Intersection returns a new array (Slice) containing unique elements that are present in both input arrays. The function accepts two arrays (slices) and returns a new array with the Intersection of unique elements. If either of the inputs is not a Slice, the function returns an error.

func IsContainsArray

func IsContainsArray(array, element interface{}) (bool, error)

IsContainsArray checks if a given element is present in the array. The function accepts an array (Slice) and an element of any type (interface{}) and returns true if the element is found in the array, false otherwise. If the array or element is of an unsupported type, the function returns an error.

func Join

func Join(array interface{}, separator string) (string, error)

Join takes an array (Slice) of elements and a separator string, and returns a single string by joining the elements with the separator.

func Last

func Last(array interface{}) interface{}

Last returns the Last element of an array (Slice). The function accepts an array (Slice) and returns its Last element. If the input is not a Slice or if the array is empty, the function returns nil.

func LastIndexOf

func LastIndexOf(array, inputSearch interface{}, fromIndex ...int) (int, error)

LastIndexOf searches for the Last occurrence of the given inputSearch value within the array (Slice) and returns its index. The search starts from the end of the array or from the specified fromIndex if provided.

func Nth

func Nth(array interface{}, number int) (interface{}, error)

Nth returns the element at the specified index from the array (Slice). The index is 1-based, so the first element is at index 1.

func PullAll

func PullAll(array, removes interface{}) (interface{}, error)

PullAll removes all occurrences of specified elements from the array (Slice).

func PullAt

func PullAt(array interface{}, indexes []int) (interface{}, error)

PullAt removes elements from the input array at specified indexes and returns the modified array. It takes an array-like data structure and a list of indexes to Remove. The function returns the modified array and an error if any occurs.

func Remove

func Remove(array interface{}, predicate interface{}) (interface{}, interface{}, error)

Remove elements from the input array based on a given predicate function. It takes an array-like data structure and a predicate function that determines whether an element should be removed. The function returns the modified array and an error if any occurs.

func Reverse

func Reverse(array interface{}) (interface{}, error)

Reverse reverses the elements in the input array. It takes an array-like data structure and returns the modified array with reversed elements. The function returns the modified array and an error if any occurs.

func Slice

func Slice(array interface{}, start, end int) (interface{}, error)

Slice extracts a sub-Slice from the input array, starting from the 'start' index (inclusive) up to the 'end' index (exclusive). It takes an array-like data structure, the start index, and the end index as arguments. The function returns the sub-Slice and an error if any occurs.

func SortedUniq

func SortedUniq(array interface{}) (interface{}, error)

SortedUniq returns a new Slice with only unique elements from the sorted input Slice. It takes an array-like data structure as input, assumes that the input Slice is sorted, and returns a new Slice containing only unique elements. The function returns the new Slice and an error if any occurs.

func Tail

func Tail(array interface{}) (interface{}, error)

Tail returns a new Slice containing all elements of the input array except the first one. It takes an array-like data structure as input and returns a new Slice excluding the first element. The function returns the new Slice and an error if any occurs.

func Take

func Take(array interface{}, number ...int) (interface{}, error)

Take returns a new Slice containing the first 'number' elements from the input array. It takes an array-like data structure and an optional number of elements to Take. If 'number' is not provided or is greater than the length of the array, all elements are taken. The function returns the new Slice and an error if any occurs.

func TakeRight

func TakeRight(array interface{}, number ...int) (interface{}, error)

TakeRight returns a new Slice containing the Last 'number' elements from the input array. It takes an array-like data structure and an optional number of elements to Take. If 'number' is not provided or is greater than the length of the array, all elements are taken. The function returns the new Slice and an error if any occurs.

func Union

func Union(arrays ...interface{}) (interface{}, error)

Union returns a new Slice that contains the unique elements from multiple input arrays. It takes variadic arguments representing array-like data structures and returns a new Slice containing unique elements from all input arrays combined. The function returns the new Slice and an error if any occurs.

func Without

func Without(array interface{}, values ...interface{}) (interface{}, error)

Without returns a new Slice that excludes specified values from the input array. It takes an array-like data structure and a variable number of values to be excluded. The function returns the new Slice Without the specified values and an error if any occurs.

func Xor

func Xor(arrays ...interface{}) (interface{}, error)

Xor returns a new Slice that contains the elements that appear in an odd number of input arrays. It takes variadic arguments representing array-like data structures and returns a new Slice containing elements that are present in an odd number of input arrays. The function returns the new Slice and an error if any occurs.

Types

This section is empty.

Jump to

Keyboard shortcuts

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