Documentation
¶
Index ¶
- func Any[T any](slice []T, predicate func(T) bool) bool
- func Contains[T comparable](slice []T, item T) bool
- func Copy[S Slice[T], T any](slice S) S
- func Count[T any](slice []T, predicate func(T) bool) int
- func Filter[T any](slice []T, predicate func(T) bool) []T
- func Find[T any](arr []T, predicate func(T) bool) (T, bool)
- func FindIndex[T any](slice []T, predicate func(T) bool) int
- func First[S Slice[T], T any](slice S) T
- func For[T any](i int, f func(int) T) []T
- func ForEach[T any](slice []T, f func(T))
- func ForEach_m[T any](slice []T, f func(*T))
- func IsEmpty[S Slice[T], T any](slice S) bool
- func IsInBounds[T any](slice []T, index int) bool
- func Last[S Slice[T], T any](slice S) T
- func Map[T, U any](slice []T, f func(T) U) []U
- func Map_i[T, U any](slice []T, f func(T, int) U) []U
- func Max[S Slice[T], T cmp.Ordered](slice S) T
- func Max_i[S Slice[T], T cmp.Ordered](slice S) (T, int)
- func Middle[S Slice[T], T any](slice S) T
- func Min[S Slice[T], T cmp.Ordered](slice S) T
- func Min_i[S Slice[T], T cmp.Ordered](slice S) (T, int)
- func Product[S Slice[T], T types.Number](slice S) T
- func Reduce[T any](slice []T, f func(T, T) T, initialValue T) T
- func Reduce_i[T any](slice []T, f func(T, T, int) T, initialValue T) T
- func RemoveNth[T any](slice []T, index int) []T
- func Repeat[T any](element T, n int) []T
- func Sum[S Slice[T], T types.Summable](slice S) T
- func Swap[T any](slice []T, i, j int)
- func ToMap[K comparable, V any](keys []K, values []V) map[K]V
- func ZipWith[T, U, V any](slice1 []T, slice2 []U, f func(T, U) V) []V
- type Slice
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Any ¶
Any returns true if at least one element in the slice satisfies the predicate and false otherwise. It returns true at the first element that satisfies the predicate, and does not check the rest of the elements
func Contains ¶
func Contains[T comparable](slice []T, item T) bool
Contains returns true if the item is in the slice and false otherwise
func FindIndex ¶
FindIndex returns the index of the first element that satisfies the predicate and -1 if no element satisfies the predicate
func ForEach ¶
func ForEach[T any](slice []T, f func(T))
ForEach applies the function f to each element of the slice
func ForEach_m ¶
func ForEach_m[T any](slice []T, f func(*T))
ForEach_m applies the function f to each element of the slice. The function f receives a pointer to the element as an argument
func IsInBounds ¶
IsInBounds returns true if the index is within the bounds of the slice and false otherwise
func Map ¶
func Map[T, U any](slice []T, f func(T) U) []U
Map applies the function f to each element of the slice and returns a new slice with the results
func Map_i ¶
Map_i applies the function f to each element of the slice and returns a new slice with the results. The function f receives the index of the element as a second argument
func Middle ¶
Middle returns the middle element of the slice. If the slice has an even number of elements, it returns the first element of the second half. If the slice is empty, it panics
func Reduce ¶
func Reduce[T any](slice []T, f func(T, T) T, initialValue T) T
Reduce applies the function f to the elements of the slice and returns a single value. The function f receives the accumulated value and the current element as arguments
func Reduce_i ¶
Reduce_i applies the function f to the elements of the slice and returns a single value. The function f receives the index of the element as a third argument
func RemoveNth ¶
RemoveNth returns a new slice with the element at the given index removed If the index is out of bounds, it panics
func Swap ¶
Swap swaps the elements at the given indices in the slice. If the indices are out of bounds, it panics
func ToMap ¶
func ToMap[K comparable, V any](keys []K, values []V) map[K]V
ToMap converts two slices into a map. The first slice contains the keys and the second slice contains the values. If the slices have different lengths, it panics