Documentation ¶
Index ¶
- func All[T any](s []T, fn func(T) bool) bool
- func Any[T any](s []T, fn func(T) bool) bool
- func Chunk[T any](s []T, chunkSize int) [][]T
- func Concat[T any](s1, s2 []T) []T
- func Count[T any](s []T, fn func(T) bool) int
- func Distinct[T comparable](s []T) []T
- func DistinctFunc[T any, U comparable](s []T, fn func(T) U) []T
- func Drop[T any](s []T, n int) []T
- func Filter[T any](s []T, fn func(T) bool) []T
- func Flatten[T any](s [][]T) []T
- func ForEach[T any](s []T, fn func(T))
- func IndexOf[T comparable](s []T, elem T) int
- func Map[T, U any](s []T, fn func(T) U) []U
- func Partition[T any](s []T, fn func(T) bool) (yes, no []T)
- func Reduce[T, U any](s []T, fn func(U, T) U, initial U) U
- func Reverse[T any](s []T)
- func RotateLeft[T any](s []T, positions int)
- func RotateRight[T any](s []T, positions int)
- func Shuffle[T any](s []T)
- func Take[T any](s []T, n int) []T
- func TakeWhile[T any](s []T, fn func(T) bool) []T
- func Zip[T, U, V any](s1 []T, s2 []U, fn func(T, U) V) []V
- func ZipShortest[T, U, V any](s1 []T, s2 []U, fn func(T, U) V) []V
- func ZipWithIndex[T, U any](s []T, fn func(int, T) U) []U
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Chunk ¶
Chunk returns a new slice containing slices of size chunkSize. The last slice may have fewer than chunkSize elements.
func Concat ¶
func Concat[T any](s1, s2 []T) []T
Concat returns a new slice containing all the elements of s1 followed by all the elements of s2.
func Distinct ¶
func Distinct[T comparable](s []T) []T
Distinct returns a new slice containing only the unique elements of s.
func DistinctFunc ¶
func DistinctFunc[T any, U comparable](s []T, fn func(T) U) []T
DistinctFunc returns a new slice containing only the unique elements of s. The function fn is used to determine the uniqueness of each element. The function fn should return a value that can be used as a key in a map.
func Drop ¶
Drop returns a new slice containing all but the first n elements of s. This is the opposite of Take. If n is greater than the length of s, Drop returns nil.
func Filter ¶
Filter returns a new slice containing only the elements that satisfy the predicate fn.
func Flatten ¶
func Flatten[T any](s [][]T) []T
Flatten returns a new slice containing all the elements of the sub-slices in s.
func ForEach ¶ added in v1.0.1
func ForEach[T any](s []T, fn func(T))
ForEach applies the function fn to each element of s.
func IndexOf ¶
func IndexOf[T comparable](s []T, elem T) int
IndexOf returns the index of the first occurrence of elem in s. If elem is not in s, IndexOf returns -1.
func Map ¶
func Map[T, U any](s []T, fn func(T) U) []U
Map returns a new slice containing the results of applying the function fn to each element of the original slice.
func Partition ¶
Partition returns two slices, the first containing the elements of s that satisfy the predicate fn, and the second containing the rest.
func Reduce ¶
func Reduce[T, U any](s []T, fn func(U, T) U, initial U) U
Reduce applies the function fn to each element of the slice, accumulating the result. The accumulated value is initialized to initial.
func RotateLeft ¶
RotateLeft rotates the elements of s to the left by positions. It does nothing if s has fewer than 2 elements. This is useful for working with circular buffers.
func RotateRight ¶
RotateRight rotates the elements of s to the right by positions. It does nothing if s has fewer than 2 elements. This is useful for working with circular buffers.
func Take ¶
Take returns the first n elements of s. If n is greater than the length of s, Take returns s unchanged.
func TakeWhile ¶
TakeWhile returns a new slice containing the elements that satisfy the predicate fn. The predicate is evaluated until the first element that does not satisfy the predicate.
func Zip ¶
func Zip[T, U, V any](s1 []T, s2 []U, fn func(T, U) V) []V
Zip returns a new slice containing the result of applying the function fn to the elements of s1 and s2. The function fn should take two arguments, one from each slice, and return a value. s1 and s2 must have the same length.
func ZipShortest ¶
func ZipShortest[T, U, V any](s1 []T, s2 []U, fn func(T, U) V) []V
ZipLongest returns a new slice containing the result of applying the function fn to the elements of s1 and s2. The function fn should take two arguments, one from each slice, and return a value. If the slices have different lengths, the result will have the length of the shorter slice.
func ZipWithIndex ¶
ZipWithIndex returns a new slice containing the result of applying the function fn to the elements of s and their index. The function fn should take two arguments, the index and the element, and return a value.
Types ¶
This section is empty.