Documentation
¶
Overview ¶
Package collections provides generic filtering and searching utilities for filterable and named items.
Index ¶
- func FilterMap[T models.NamedFilterable](g map[string][]T, key *string, name *string, filter string, pred func(T) bool) map[string][]T
- func FilterMapOrAll[T models.NamedFilterable](g map[string][]T, filter string) map[string][]T
- func FilterSlice[T models.NamedFilterable](items []T, name *string, filter string, pred func(T) bool) []T
- func FindByName[T models.NamedItem](items []T, name string) *T
- func IsMatch(item models.Filterable, filter string, ignoreCase bool) bool
- func TruncateSlice[T any](items []T, limit int) []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FilterMap ¶
func FilterMap[T models.NamedFilterable]( g map[string][]T, key *string, name *string, filter string, pred func(T) bool, ) map[string][]T
FilterMap returns a map of filtered items from the input map, filtered by key, name, filter, and an optional predicate.
func FilterMapOrAll ¶ added in v0.2.0
func FilterMapOrAll[T models.NamedFilterable](g map[string][]T, filter string) map[string][]T
FilterMapOrAll returns g unchanged when filter is empty, and a filtered copy otherwise. Useful for the common case where callers want "all rows when no filter is set" without conditional plumbing at every callsite.
func FilterSlice ¶
func FilterSlice[T models.NamedFilterable](items []T, name *string, filter string, pred func(T) bool) []T
FilterSlice returns a slice of items that match the filter and name. If pred is non-nil, the item must also satisfy pred(item).
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 TruncateSlice ¶ added in v0.4.0
TruncateSlice returns items[:limit] when limit > 0 and the slice has more items than the limit; otherwise returns items unchanged. A non-positive limit means "no limit" (matches kubectl --limit=0 convention) so callers can pass an unbound limit through without a special branch.
Truncation always happens AFTER filtering: with the toolkit's fuzzy substring filter being client-side, "filter + limit" only makes sense as "first N matching the filter". Source-side `ListOptions.Limit` would silently break that contract when filter is set (the K8s API returns the first N by its own ordering, only some of which match the filter).
Types ¶
This section is empty.