Documentation ¶
Index ¶
- func All[T any](list []T, predicate func(T) bool) bool
- func Any[T any](list []T, predicate func(T) bool) bool
- func Contains[T comparable](list []T, elem T) bool
- func ContainsWith[T any, K comparable](list []T, elem T, keyFn func(T) K) bool
- func Deduplicate[T comparable](list []T) []T
- func DeduplicateWith[T any, K comparable](list []T, keyFn func(T) K) []T
- func Filter[T any](list []T, predicate func(T) bool) []T
- func Flatten[T any](list [][]T) []T
- func GroupBy[T any, K comparable](list []T, keyFn func(T) K) map[K][]T
- func If[T any](cond bool, ifVal, elseVal T) T
- func IfElse[T any](cond bool, ifFn, elseFn func() T) T
- func IfThen[T any](cond bool, val T, apply func(T) T) T
- func Map[T, U any](list []T, mapper func(T) U) []U
- func Max[T number](list []T) (val T, ok bool)
- func MaxWith[T any](list []T, less func(t1, t2 T) bool) (val T, ok bool)
- func Min[T number](list []T) (val T, ok bool)
- func MinWith[T any](list []T, less func(t1, t2 T) bool) (val T, ok bool)
- func None[T any](list []T, predicate func(T) bool) bool
- func Partition[T any](list []T, predicate func(T) bool) (satisfied, unsatisfied []T)
- func Reverse[T any](list []T) []T
- func Sum[T number](list []T) T
- func TopK[T any](list []T, k int, cmp func(t1, t2 T) int) []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
func Contains[T comparable](list []T, elem T) bool
Contains is a function that checks if a slice contains an element.
func ContainsWith ¶
func ContainsWith[T any, K comparable](list []T, elem T, keyFn func(T) K) bool
ContainsWith is a function that checks if a slice contains an element based on a key function.
func Deduplicate ¶
func Deduplicate[T comparable](list []T) []T
Deduplicate is a function that removes duplicates from a slice.
func DeduplicateWith ¶
func DeduplicateWith[T any, K comparable](list []T, keyFn func(T) K) []T
DeduplicateWith is a function that removes duplicates from a slice based on a key function.
func Flatten ¶
func Flatten[T any](list [][]T) []T
Flatten is a function that flattens a slice of slices.
func GroupBy ¶
func GroupBy[T any, K comparable](list []T, keyFn func(T) K) map[K][]T
GroupBy is a function that groups elements in a slice by a common value, generated by a provided function.
func If ¶
If is a function that returns a value if the condition is true, otherwise returns another value.
func IfElse ¶
IfElse is a function that returns a value if the condition is true, otherwise returns the result of another function.
func IfThen ¶
IfThen is a function that applies a function to a value if the condition is true, otherwise returns the value.
func Map ¶
func Map[T, U any](list []T, mapper func(T) U) []U
Map is a function that maps a list of items to another list of items based on a function.
func Max ¶
func Max[T number](list []T) (val T, ok bool)
Max is a function that returns the maximum element in a slice.
func MaxWith ¶
MaxWith is a function that returns the maximum element in a slice based on a comparison function.
func Min ¶
func Min[T number](list []T) (val T, ok bool)
Min is a function that returns the minimum element in a slice.
func MinWith ¶
MinWith is a function that returns the minimum element in a slice based on a comparison function.
func Partition ¶
Partition is a function that partitions a slice into two slices based on a predicate function. The first slice contains elements that satisfy the predicate, and the second slice contains elements that do not.
func Sum ¶
func Sum[T number](list []T) T
Sum is a function that returns the sum of elements in a slice.
Types ¶
This section is empty.