Documentation
¶
Overview ¶
Package collections provides generic collection utilities for filtering and sorting.
Index ¶
- func Filter[T any](items []T, keep func(T) bool) []T
- func FilterMap[T models.NamedFilterable, R any](g map[string][]T, key *string, name *string, filter string, ...) []R
- func FilterSlice[T models.NamedFilterable](items []T, name *string, filter string, action func(int, T) bool)
- func FindByName[T models.NamedItem](items []T, name string) *T
- func IsMatch(item models.Filterable, filter string, ignoreCase bool) bool
- func Map[T any, R any](items []T, f func(T) R) []R
- func SortBy[T any](items []T, less func(a, b T) bool)
- func SortKeyedItems[T interface{ ... }](items []T)
- func SortNamedItems[T interface{ ... }](items []T)
- func Unique[T comparable](items []T) []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FilterMap ¶
func FilterMap[T models.NamedFilterable, R any](g map[string][]T, key *string, name *string, filter string, transform func(string, T) R, ) []R
FilterMap applies the transform function to all items in the map that match the key, name, and filter, returning a slice of results.
func FilterSlice ¶
func FilterSlice[T models.NamedFilterable](items []T, name *string, filter string, action func(int, T) bool, )
FilterSlice performs the given action on items in the slice that match the filter and name. Return false in the action to stop further processing.
func FindByName ¶
FindByName returns a pointer to the item with the given name, or nil if not found.
func IsMatch ¶
func IsMatch(item models.Filterable, filter string, ignoreCase bool) bool
IsMatch returns true if the item matches the filter string, optionally ignoring case.
func SortKeyedItems ¶
func SortKeyedItems[T interface{ GetKey() string }](items []T)
SortKeyedItems sorts a slice of items implementing GetKey() by key in ascending order. T must implement GetKey() string.
func SortNamedItems ¶
func SortNamedItems[T interface{ GetName() string }](items []T)
SortNamedItems sorts a slice of items implementing GetName() by name in ascending order. T must implement GetName() string.
func Unique ¶
func Unique[T comparable](items []T) []T
Unique returns a new slice with duplicate elements removed, preserving order.
Types ¶
This section is empty.