list

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[T any](items []T, ok func(T) bool) bool

All checks if all list items pass the ok function

func AllEqual

func AllEqual[T comparable](items []T, item T) bool

AllEqual checks if all list items are equal to given value

func AllFalse

func AllFalse(items []bool) bool

AllFalse checks if all list items are false

func AllGreater

func AllGreater[T cmp.Ordered](items []T, value T) bool

AllGreater checks if all list items are greater than given value

func AllGreaterEqual

func AllGreaterEqual[T cmp.Ordered](items []T, value T) bool

AllGreaterEqual checks if all list items are greater or equal to given value

func AllIndexFunc

func AllIndexFunc[T any](items []T, itemFn func(T) bool) []int

AllIndexFunc returns all indexes of item in the list, using the item function

func AllIndexOf

func AllIndexOf[T comparable](items []T, item T) []int

AllIndexOf gets all indexes of given item

func AllIndexed

func AllIndexed[T any](items []T, ok func(int, T) bool) bool

AllIndexed checks if all list item passes the ok function: (index, item)

func AllLesser

func AllLesser[T cmp.Ordered](items []T, value T) bool

AllLesser checks if all list items are lesser than given value

func AllLesserEqual

func AllLesserEqual[T cmp.Ordered](items []T, value T) bool

AllLesserEqual checks if all list items are lesser or equal to given value

func AllSame

func AllSame[T comparable](items []T) bool

AllSame checks if all list items are same

func AllSameFunc

func AllSameFunc[T any, K comparable](items []T, keyFn func(T) K) bool

AllSameFunc checks if all list key values are same

func AllTrue

func AllTrue(items []bool) bool

AllTrue checks if all list items are true

func AllUnique

func AllUnique[T comparable](items []T) bool

AllUnique checks if all list items are unique

func AllUniqueFunc

func AllUniqueFunc[T any, K comparable](items []T, keyFn func(T) K) bool

AllUniqueFunc checks if all list key values are unique

func Any

func Any[T any](items []T, ok func(T) bool) bool

Any checks if list has an item that passes the ok function

func AnyFalse

func AnyFalse(items []bool) bool

AnyFalse checks if any list item is false

func AnyIndexed

func AnyIndexed[T any](items []T, ok func(int, T) bool) bool

AnyIndexed checks if any list item passes the ok function: (index, item)

func AnyTrue

func AnyTrue(items []bool) bool

AnyTrue checks if any list item is true

func Apply

func Apply[T any](items []T, task func(T) T) []T

Apply applies the task function to each item

func ArgMax

func ArgMax[T cmp.Ordered](items []T) int

ArgMax finds the index of maximum item on the list. Returns -1 if list is empty

func ArgMin

func ArgMin[T cmp.Ordered](items []T) int

ArgMin finds the index of minimum item on the list. Returns -1 if list is empty

func Cap

func Cap[T any](items []T) int

Cap returns the list capacity

func Copy

func Copy[T any](items []T) []T

Copy creates a new list with copied items

func Count

func Count[T comparable](items []T, item T) int

Count counts the number of occurrence of item in the list

func CountFunc

func CountFunc[T any](items []T, ok func(T) bool) int

CountFunc counts the number of items that passes the ok function

func CountUnique

func CountUnique[T comparable](items []T) int

CountUnique counts the number of unique items in list

func CountUniqueFunc

func CountUniqueFunc[T any, K comparable](items []T, keyFn func(T) K) int

CountUniqueFunc counts the number of unique key values in the list, using the key function

func Deduplicate

func Deduplicate[T comparable](items []T) []T

Deduplicate removes duplicates from the list, preserving item order

func DeduplicateFunc

func DeduplicateFunc[T any, K comparable](items []T, keyFn func(T) K) []T

DeduplicateFunc removes duplicate key values from the list, preserving item order, using the key function

func Filter

func Filter[T any](items []T, keep func(T) bool) []T

Filter filters the list by only keeping items that pass the keep function

func FilterIndexed

func FilterIndexed[T any](items []T, keep func(int, T) bool) []T

FilterIndexed filters the list by only keeping items that pass the keep function: (index, item)

func GetFuncOrDefault

func GetFuncOrDefault[T any](items []T, itemFn func(T) bool, defaultValue T) T

GetFuncOrDefault returns the first item that passes the item function, or returns the default value

func GetOrDefault

func GetOrDefault[T comparable](items []T, item T, defaultValue T) T

GetOrDefault returns the first item that matches given item, or returns default value

func GetRandom

func GetRandom[T any](items []T) (T, bool)

GetRandom gets a random item from List, and a flag which indicates if it is valid

func GroupByFunc

func GroupByFunc[T any, K comparable](items []T, keyFn func(T) K) map[K][]T

GroupByFunc groups the list items using the key function

func Has

func Has[T comparable](items []T, item T) bool

Has checks if any list items are equal to given value

func HasNo

func HasNo[T comparable](items []T, item T) bool

HasNo checks if no list items are equal to given value

func InclusiveRange

func InclusiveRange[T number.Integer](first, last T) []T

InclusiveRange creates a new list, with numbers from [first, last]

func IndexFunc

func IndexFunc[T any](items []T, itemFn func(T) bool) int

IndexFunc returns the index of item (or -1 if not in list), using the item function

func IndexLookup

func IndexLookup[T comparable](items []T) map[T]int

IndexLookup creates a lookup of { item : index } from list. This loses data if list items are not unique

func IndexOf

func IndexOf[T comparable](items []T, item T) int

IndexOf gets the index of given item, returns -1 if not in list

func IsEmpty

func IsEmpty[T any](items []T) bool

IsEmpty checks if list is empty

func Last

func Last[T any](items []T, rank int) (T, bool)

Last returns the nth item from the back of the list (starts at 1), and a flag which indicates if it is valid

func LastIndex

func LastIndex[T any](items []T) int

LastIndex returns the list last index

func Len

func Len[T any](items []T) int

Len returns the list length

func Map

func Map[T, V any](items []T, convert func(T) V) []V

Map applies the convert function for each list item

func MapIf

func MapIf[T, V any](items []T, convert func(T) (V, bool)) []V

MapIf combines Map and Filter: apply the convert function, and filter items based on result flag

func MapIndexed

func MapIndexed[T, V any](items []T, convert func(int, T) V) []V

MapIndexed applies the convert function for each indexed item

func MapIndexedIf

func MapIndexedIf[T, V any](items []T, convert func(int, T) (V, bool)) []V

MapIndexedIf combines Map and Filter: apply the convert function (index, item), and filter items based on result flag

func MapList

func MapList[T any](indexes []int, items []T) []T

MapList maps the indexes to list items. Can have zero values for invalid indexes

func MapLookup

func MapLookup[K comparable, V any](keys []K, lookup map[K]V) []V

MapLookup maps the keys to given lookup map. Can have zero values for invalid keys

func MustGetRandom

func MustGetRandom[T any](items []T) T

MustGetRandom gets a random item from List, and panics if list is empty

func MustLast

func MustLast[T any](items []T, rank int) T

MustLast returns the nth item from the back of the list (starts at 1). Panics if rank is not 1 <= rank <= N, where N = length of List.

func NewEmpty

func NewEmpty[T any](capacity int) []T

NewEmpty creates an empty list with given capacity

func NotAny

func NotAny[T any](items []T, ok func(T) bool) bool

NotAny checks if list has no item that passes the ok function

func NotAnyIndexed

func NotAnyIndexed[T any](items []T, ok func(int, T) bool) bool

NotAnyIndexed checks if no list item passes the ok function: (index, item)

func NotEmpty

func NotEmpty[T any](items []T) bool

NotEmpty checks if list is not empty

func Product

func Product[T number.Type](numbers []T) T

Product computes the product of number items

func Range

func Range[T number.Integer](start, end T) []T

Range creates a new list, with numbers from [start, end)

func Reduce

func Reduce[T any](items []T, initial T, reducer func(T, T) T) T

Reduce applies the reducer to each item to get the final result. The reducer function has the signature (result, item) => result

func Remove

func Remove[T comparable](items []T, item T) ([]T, bool)

Remove removes the first item from list that matches given item

func RemoveAll

func RemoveAll[T comparable](items []T, item T) []T

RemoveAll removes all items from list that matches given item

func RemoveAllFunc

func RemoveAllFunc[T any](items []T, itemFn func(T) bool) []T

RemoveAllFunc removes all items from list that passes the item function

func RemoveFunc

func RemoveFunc[T any](items []T, itemFn func(T) bool) ([]T, bool)

RemoveFunc removes the first item from list that passes the item function

func RepeatedItem

func RepeatedItem[T any](value T, count int) []T

RepeatedItem creates a new list, with <value> repeated <count> times

func Shuffle

func Shuffle[T any](items []T)

Shuffle shuffles the List in place

func Sum

func Sum[T number.Type](numbers []T) T

Sum computes the sum of number items

func SumOf

func SumOf[T any, V number.Type](items []T, convert func(T) V) V

SumOf computes the sum of mapped number items

func Tally

func Tally[T comparable](items []T) map[T]int

Tally computes the number of occurrence of each item in list

func TallyFunc

func TallyFunc[T any, K comparable](items []T, keyFn func(T) K) map[K]int

TallyFunc computes the number of occurrence of each key value in the list, using the key function

func ToAny

func ToAny[T any](items []T) []any

ToAny creates a list of <any> items from the list

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL