Documentation
¶
Overview ¶
Package list contains list-related functions.
Index ¶
- func All[T any](items []T, ok func(T) bool) bool
- func AllEqual[T comparable](items []T, value T) bool
- func AllFalse(items []bool) bool
- func AllGreater[T cmp.Ordered](items []T, value T) bool
- func AllGreaterEqual[T cmp.Ordered](items []T, value T) bool
- func AllLess[T cmp.Ordered](items []T, value T) bool
- func AllLessEqual[T cmp.Ordered](items []T, value T) bool
- func AllNotEqual[T comparable](items []T, value T) bool
- func AllSame[T comparable](items []T) bool
- func AllTrue(items []bool) bool
- func AllUnique[T comparable](items []T) bool
- func Any[T any](items []T, ok func(T) bool) bool
- func AnyEqual[T comparable](items []T, value T) bool
- func AnyFalse(items []bool) bool
- func AnyTrue(items []bool) bool
- func Apply[T any](items []T, task func(T) T) []T
- func ArgMax[T cmp.Ordered](items []T) int
- func ArgMin[T cmp.Ordered](items []T) int
- func Copy[T any](items []T) []T
- func Count[T comparable](items []T, value T) int
- func Deduplicate[T comparable](items []T) []T
- func Divide(numItems, numParts int) [][2]int
- func DivideRoundRobin[T any](items []T, numParts int) [][]T
- func Filter[T any](items []T, keep func(T) bool) []T
- func GroupBy[T any, K comparable](items []T, keyFn func(T) K) map[K][]T
- func GroupByFunc[T, V any, K comparable](items []T, keyFn func(T) K, valueFn func(T) V) map[K][]V
- func IndexMap[T comparable](items []T) map[T]int
- func IndexedAll[T any](items []T, ok func(int, T) bool) bool
- func IndexedAny[T any](items []T, ok func(int, T) bool) bool
- func IndexedFilter[T any](items []T, keep func(int, T) bool) []T
- func IndexedMap[T, V any](items []T, convert func(int, T) V) []V
- func IsEmpty[T any](items []T) bool
- func Last[T any](items []T, index int) T
- func Length[T any](items []T) int
- func LookupIndex[T any](items []T) func(int) T
- func Map[T, V any](items []T, convert func(T) V) []V
- func MapIf[T, V any](items []T, convert func(T) (V, bool)) []V
- func MapList[T any](indexes []int, values []T) []T
- func NotEmpty[T any](items []T) bool
- func NumRange[T ~uint | ~int](start, end T) []T
- func Product[T number](items []T) T
- func Random[T any](items []T) T
- func Reduce[T any](items []T, reduce func(T, T) T, initial T) T
- func Repeated[T any](value T, count int) []T
- func Shuffle[T any](items []T)
- func Sum[T number](items []T) T
- func SumOf[T any, V number](items []T, convert func(T) V) V
- func TallyFunc[T any, K comparable](items []T, keyFn func(T) K) map[K]int
- func TallyItems[T comparable](items []T) map[T]int
- func ToAny[T any](items []T) []any
- func Translate[K comparable, V any](items []K, mask map[K]V) []V
- type SyncList
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllEqual ¶
func AllEqual[T comparable](items []T, value T) bool
Check if all list items are equal to the given value
func AllGreater ¶
Check if all list items are greater than given value
func AllGreaterEqual ¶
Check if all list items are greater or equal than given value
func AllLessEqual ¶
Check if all list items are lesser or equal than given value
func AllNotEqual ¶
func AllNotEqual[T comparable](items []T, value T) bool
Check if all list items are not equal to the given value
func AnyEqual ¶
func AnyEqual[T comparable](items []T, value T) bool
Check if any list item is equal to the given value
func Count ¶
func Count[T comparable](items []T, value T) int
Count the number of occurences of given value in the list
func Deduplicate ¶
func Deduplicate[T comparable](items []T) []T
Deduplicate list, preserving given order
func Divide ¶
Divides the number of items by the number of parts (divide workload). Return the index ranges of each part
func DivideRoundRobin ¶
Divides the items into parts using round-robin order. Returns the divided items for each part
func GroupBy ¶
func GroupBy[T any, K comparable](items []T, keyFn func(T) K) map[K][]T
Group items using the key function
func GroupByFunc ¶
func GroupByFunc[T, V any, K comparable](items []T, keyFn func(T) K, valueFn func(T) V) map[K][]V
Group items using the key function, and map the item using the value function
func IndexMap ¶
func IndexMap[T comparable](items []T) map[T]int
Return map of item => index, loses data if items are not unique
func IndexedAll ¶
Check if all list items pass the ok function (accepts index and item)
func IndexedAny ¶
Check if any list item passes the ok function (accepts index and item)
func IndexedFilter ¶
Filter list: only keep items with index that pass keep function
func IndexedMap ¶
Apply convert function to each list item with index, return mapped items
func LookupIndex ¶
Creates a converter function that maps the index to the list value, Panics on invalid index
func Map ¶
func Map[T, V any](items []T, convert func(T) V) []V
Apply convert function to each list item, return mapped items
func MapIf ¶
Apply convert function to each list item, but only if second result is true, return mapped & filtered items
func MapList ¶
Map list indexes to given values; return mapped items. Can have zero value if index is invalid
func Reduce ¶
func Reduce[T any](items []T, reduce func(T, T) T, initial T) T
Apply reduce function to each item
func SumOf ¶
func SumOf[T any, V number](items []T, convert func(T) V) V
Computes sum of mapped items
func TallyFunc ¶
func TallyFunc[T any, K comparable](items []T, keyFn func(T) K) map[K]int
Tally the number of occurences of each item in the list, using the keyFn
func TallyItems ¶
func TallyItems[T comparable](items []T) map[T]int
Tally the number of occurences of each item in the list
func Translate ¶
func Translate[K comparable, V any](items []K, mask map[K]V) []V
Apply the translation mask to each list item, return mapped items. Can have zero value if item is not in mask map
Types ¶
type SyncList ¶
type SyncList[T any] struct { // contains filtered or unexported fields }
Concurrency-safe generic list
func SyncListFrom ¶
Create SyncList from existing list
func (*SyncList[T]) ClearItems ¶
func (sl *SyncList[T]) ClearItems() []T
Copy SyncList's items and clear it