Documentation
¶
Index ¶
- func All[T any](input []T, predicate func(T) bool) bool
- func Any[T any](input []T, predicate func(T) bool) bool
- func Associate[T any, K comparable, V any](input []T, transform func(T) (K, V)) map[K]V
- func Chunk[T any](input []T, size int) [][]T
- func Contains[T comparable](input []T, value T) bool
- func Count[T any](input []T, predicate func(T) bool) int
- func Distinct[T comparable](input []T) []T
- func DistinctBy[T any, K comparable](input []T, keySelector func(T) K) []T
- func Drop[T any](input []T, n int) []T
- func DropWhile[T any](input []T, predicate func(T) bool) []T
- func Filter[T any](input []T, predicate func(T) bool) []T
- func Find[T any](input []T, predicate func(T) bool) (T, bool)
- func FindIndex[T any](input []T, predicate func(T) bool) int
- func FlatMap[T any, U any](input []T, mapper func(T) []U) []U
- func Flatten[T any](input [][]T) []T
- func ForEach[T any](input []T, action func(T))
- func ForEachIndexed[T any](input []T, action func(int, T))
- func GroupBy[T any, K comparable](input []T, keySelector func(T) K) map[K][]T
- func IndexOf[T comparable](input []T, value T) int
- func Keys[K comparable, V any](m map[K]V) []K
- func Map[T any, U any](input []T, mapper func(T) U) []U
- func Max[T cmp.Ordered](input []T) (T, bool)
- func MaxBy[T any](input []T, less func(a, b T) int) (T, bool)
- func Min[T cmp.Ordered](input []T) (T, bool)
- func MinBy[T any](input []T, less func(a, b T) int) (T, bool)
- func None[T any](input []T, predicate func(T) bool) bool
- func Partition[T any](input []T, predicate func(T) bool) (truePart []T, falsePart []T)
- func Reduce[T any, U any](input []T, reducer func(U, T) U, initial U) U
- func Reverse[T any](input []T) []T
- func SortBy[T any](input []T, cmpFn func(a, b T) int) []T
- func Sum[T Numeric](input []T) T
- func SumBy[T any, N Numeric](input []T, selector func(T) N) N
- func Take[T any](input []T, n int) []T
- func TakeWhile[T any](input []T, predicate func(T) bool) []T
- func ToMap[T any, K comparable](input []T, keySelector func(T) K) map[K]T
- func Unzip[T any, U any](input []Pair[T, U]) ([]T, []U)
- func Values[K comparable, V any](m map[K]V) []V
- func Zip[T any, U any](a []T, b []U) [][2]any
- func ZipWith[T any, U any, R any](a []T, b []U, combiner func(T, U) R) []R
- type Numeric
- type Pair
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func All ¶
All reports whether every element satisfies the predicate. Returns true for an empty slice.
func Associate ¶
func Associate[T any, K comparable, V any](input []T, transform func(T) (K, V)) map[K]V
Associate builds a map from the input slice using a function that returns a key-value pair for each element.
func Chunk ¶
Chunk splits the input slice into sub-slices of the given size. The last chunk may have fewer elements.
func Contains ¶
func Contains[T comparable](input []T, value T) bool
Contains reports whether the slice contains the given value.
func Distinct ¶
func Distinct[T comparable](input []T) []T
Distinct returns a new slice with duplicate elements removed. Preserves the order of first occurrence.
func DistinctBy ¶
func DistinctBy[T any, K comparable](input []T, keySelector func(T) K) []T
DistinctBy returns a new slice with duplicates removed based on a key selector. Preserves the order of first occurrence.
func Find ¶
Find returns the first element satisfying the predicate and true, or the zero value and false if none is found.
func FindIndex ¶
FindIndex returns the index of the first element satisfying the predicate, or -1 if none is found.
func FlatMap ¶
FlatMap applies a mapper that returns a slice for each element, then flattens the results into a single slice.
func Flatten ¶
func Flatten[T any](input [][]T) []T
Flatten concatenates a slice of slices into a single flat slice.
func ForEach ¶
func ForEach[T any](input []T, action func(T))
ForEach invokes the action function for each element.
func ForEachIndexed ¶
ForEachIndexed invokes the action function for each element with its index.
func GroupBy ¶
func GroupBy[T any, K comparable](input []T, keySelector func(T) K) map[K][]T
GroupBy groups elements by a key, returning a map of key → slice of elements.
func IndexOf ¶
func IndexOf[T comparable](input []T, value T) int
IndexOf returns the index of the first occurrence of value, or -1 if not found.
func Keys ¶
func Keys[K comparable, V any](m map[K]V) []K
Keys returns all keys of a map as a slice (order is not guaranteed).
func Map ¶
Map applies a mapper function to each element of the input slice, returning a new slice of the mapped results.
func Max ¶
Max returns the maximum element of an ordered slice. Returns the zero value and false if the slice is empty.
func MaxBy ¶
MaxBy returns the maximum element according to the comparison function. Returns the zero value and false if the slice is empty.
func Min ¶
Min returns the minimum element of an ordered slice. Returns the zero value and false if the slice is empty.
func MinBy ¶
MinBy returns the minimum element according to the comparison function. Returns the zero value and false if the slice is empty.
func None ¶
None reports whether no elements satisfy the predicate. Returns true for an empty slice.
func Partition ¶
Partition splits the input into two slices: elements that satisfy the predicate and elements that do not.
func Reverse ¶
func Reverse[T any](input []T) []T
Reverse returns a new slice with elements in reverse order.
func SortBy ¶
SortBy returns a new sorted slice using the provided comparison function. The cmp function should return a negative number when a < b, zero when a == b, and a positive number when a > b.
func ToMap ¶
func ToMap[T any, K comparable](input []T, keySelector func(T) K) map[K]T
ToMap builds a map by extracting keys from each element; the values are the elements themselves.
func Values ¶
func Values[K comparable, V any](m map[K]V) []V
Values returns all values of a map as a slice (order is not guaranteed).