collections

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package collections provides generic collection utilities for filtering and sorting.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter

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

Filter returns a new slice containing only the elements for which keep returns true.

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

func FindByName[T models.NamedItem](items []T, name string) *T

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 Map

func Map[T any, R any](items []T, f func(T) R) []R

Map returns a new slice by applying f to each element of items.

func SortBy

func SortBy[T any](items []T, less func(a, b T) bool)

SortBy sorts the slice in place using the provided less function.

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.

Jump to

Keyboard shortcuts

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