Documentation ¶
Index ¶
- func Concat[T any](s ...[]T) []T
- func Copy[T any](s []T) []T
- func CopyWithin[T any](s []T, target, start int, end ...int)
- func Distinct[T comparable](s *[]T, changeSlice bool) (distinctCount map[T]int)
- func Every[T any](s []T, fn func(s []T, k int, v T) bool) bool
- func Fill[T any](s []T, value T, start int, end ...int)
- func Filter[T any](s []T, fn func(s []T, k int, v T) bool) []T
- func Find[T any](s []T, fn func(s []T, k int, v T) bool) (k int, v T)
- func Includes[T comparable](s []T, valueToFind T, fromIndex ...int) bool
- func IndexOf[T comparable](s []T, searchElement T, fromIndex ...int) int
- func Intersect[T comparable](s ...[]T) (intersectCount map[T]int)
- func LastIndexOf[T comparable](s []T, searchElement T, fromIndex ...int) int
- func Map[T any](s []T, fn func(s []T, k int, v T) T) []T
- func One[T any](s []T) T
- func Pop[T any](s *[]T) (T, bool)
- func Push[T any](s *[]T, element ...T) int
- func PushDistinct[T comparable](s []T, element ...T) []T
- func Reduce[T any](s []T, fn func(s []T, k int, v, accumulator T) T, initialValue ...T) T
- func ReduceRight[T any](s []T, fn func(s []T, k int, v, accumulator T) T, initialValue ...T) T
- func RemoveEvery[T comparable](p *[]T, elements ...T) int
- func RemoveFirst[T comparable](p *[]T, elements ...T) int
- func Reverse[T any](s []T)
- func SetsDifference[T comparable](set1, set2 []T, others ...[]T) []T
- func SetsIntersect[T comparable](set1, set2 []T, others ...[]T) []T
- func SetsUnion[T comparable](set1, set2 []T, others ...[]T) []T
- func Shift[T any](s *[]T) (T, bool)
- func Slice[T any](s []T, begin int, end ...int) []T
- func Some[T any](s []T, fn func(s []T, k int, v T) bool) bool
- func Splice[T any](s *[]T, start, deleteCount int, items ...T)
- func Unshift[T any](s *[]T, element ...T) int
- func UnshiftDistinct[T comparable](s *[]T, element ...T) int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Concat ¶
func Concat[T any](s ...[]T) []T
Concat is used to merge two or more slices. This method does not change the existing slices, but instead returns a new slice.
func CopyWithin ¶
CopyWithin copies part of a slice to another location in the current slice. @target
Zero-based index at which to copy the sequence to. If negative, target will be counted from the end.
@start
Zero-based index at which to start copying elements from. If negative, start will be counted from the end.
@end
Zero-based index at which to end copying elements from. CopyWithin copies up to but not including end. If negative, end will be counted from the end. If end is omitted, CopyWithin will copy until the last index (default to len(s)).
func Distinct ¶
func Distinct[T comparable](s *[]T, changeSlice bool) (distinctCount map[T]int)
Distinct calculates the count of each different element, and only saves these different elements in place if changeSlice is true.
func Every ¶
Every tests whether all elements in the slice pass the test implemented by the provided function. NOTE:
Calling this method on an empty slice will return true for any condition!
func Fill ¶
Fill changes all elements in the current slice to a value, from a start index to an end index. @value
Zero-based index at which to copy the sequence to. If negative, target will be counted from the end.
@start
Zero-based index at which to start copying elements from. If negative, start will be counted from the end.
@end
Zero-based index at which to end copying elements from. CopyWithin copies up to but not including end. If negative, end will be counted from the end. If end is omitted, CopyWithin will copy until the last index (default to len(s)).
func Filter ¶
Filter creates a new slice with all elements that pass the test implemented by the provided function.
func Find ¶
Find returns the key-value of the first element in the provided slice that satisfies the provided testing function. NOTE:
If not found, k = -1
func Includes ¶
func Includes[T comparable](s []T, valueToFind T, fromIndex ...int) bool
Includes determines whether a slice includes a certain value among its entries. @fromIndex
The index to start the search at. Defaults to 0.
func IndexOf ¶
func IndexOf[T comparable](s []T, searchElement T, fromIndex ...int) int
IndexOf returns the first index at which a given element can be found in the slice, or -1 if it is not present. @fromIndex
The index to start the search at. Defaults to 0.
func Intersect ¶
func Intersect[T comparable](s ...[]T) (intersectCount map[T]int)
Intersect calculates intersection of two or more slices, and returns the count of each element.
func LastIndexOf ¶
func LastIndexOf[T comparable](s []T, searchElement T, fromIndex ...int) int
LastIndexOf returns the last index at which a given element can be found in the slice, or -1 if it is not present. @fromIndex
The index to start the search at. Defaults to 0.
func Map ¶
Map creates a new slice populated with the results of calling a provided function on every element in the calling slice.
func One ¶
func One[T any](s []T) T
One try to return the first element, otherwise return zero value.
func Pop ¶
Pop removes the last element from a slice and returns that element. This method changes the length of the slice.
func Push ¶
Push adds one or more elements to the end of a slice and returns the new length of the slice.
func PushDistinct ¶
func PushDistinct[T comparable](s []T, element ...T) []T
PushDistinct adds one or more new elements that do not exist in the current slice at the end.
func Reduce ¶
Reduce executes a reducer function (that you provide) on each element of the slice, resulting in a single output value. @accumulator
The accumulator accumulates callback's return values. It is the accumulated value previously returned in the last invocation of the callback—or initialValue, if it was supplied (see below).
@initialValue
A value to use as the first argument to the first call of the callback. If no initialValue is supplied, the first element in the slice will be used and skipped.
func ReduceRight ¶
ReduceRight applies a function against an accumulator and each value of the slice (from right-to-left) to reduce it to a single value. @accumulator
The accumulator accumulates callback's return values. It is the accumulated value previously returned in the last invocation of the callback—or initialValue, if it was supplied (see below).
@initialValue
A value to use as the first argument to the first call of the callback. If no initialValue is supplied, the first element in the slice will be used and skipped.
func RemoveEvery ¶
func RemoveEvery[T comparable](p *[]T, elements ...T) int
RemoveEvery removes all the elements from the slice, and returns the new length of the slice.
func RemoveFirst ¶
func RemoveFirst[T comparable](p *[]T, elements ...T) int
RemoveFirst removes the first matched elements from the slice, and returns the new length of the slice.
func SetsDifference ¶
func SetsDifference[T comparable](set1, set2 []T, others ...[]T) []T
SetsDifference calculates between multiple collections: set1 - set2 - others... This method does not change the existing slices, but instead returns a new slice.
func SetsIntersect ¶
func SetsIntersect[T comparable](set1, set2 []T, others ...[]T) []T
SetsIntersect calculates between multiple collections: set1 ∩ set2 ∩ others... This method does not change the existing slices, but instead returns a new slice.
func SetsUnion ¶
func SetsUnion[T comparable](set1, set2 []T, others ...[]T) []T
SetsUnion calculates between multiple collections: set1 ∪ set2 ∪ others... This method does not change the existing slices, but instead returns a new slice.
func Shift ¶
Shift removes the first element from a slice and returns that removed element. This method changes the length of the slice.
func Slice ¶
Slice returns a copy of a portion of a slice into a new slice object selected from begin to end (end not included) where begin and end represent the index of items in that slice. The original slice will not be modified.
func Some ¶
Some tests whether at least one element in the slice passes the test implemented by the provided function. NOTE:
Calling this method on an empty slice returns false for any condition!
func Splice ¶
Splice changes the contents of a slice by removing or replacing existing elements and/or adding new elements in place.
func Unshift ¶
Unshift adds one or more elements to the beginning of a slice and returns the new length of the slice.
func UnshiftDistinct ¶
func UnshiftDistinct[T comparable](s *[]T, element ...T) int
UnshiftDistinct adds one or more new elements that do not exist in the current slice to the beginning and returns the new length of the slice.
Types ¶
This section is empty.