list
import list "ganigeorgiev.com/pocketbase/pocketbase/tools/list"
Source: tools/list.
Functions
ExistInSlice
func ExistInSlice[T comparable](item T, list []T) bool
ExistInSlice checks whether a comparable element exists in a slice of the same type.
ExistInSliceWithRegex
func ExistInSliceWithRegex(str string, list []string) bool
ExistInSliceWithRegex checks whether a string exists in a slice either by direct match, or by a regular expression (eg. `^\w+$`).
Note: Only list items starting with '^' and ending with '$' are treated as regular expressions!
NonzeroUniques
func NonzeroUniques[T comparable](list []T) []T
NonzeroUniques returns only the nonzero unique values from a slice.
SubtractSlice
func SubtractSlice[T comparable](base []T, subtract []T) []T
SubtractSlice returns a new slice with only the "base" elements that don't exist in "subtract".
ToChunks
func ToChunks[T any](list []T, chunkSize int) [][]T
ToChunks splits list into chunks.
Zero or negative chunkSize argument is normalized to 1.
See https://go.dev/wiki/SliceTricks#batching-with-minimal-allocation.
ToInterfaceSlice
func ToInterfaceSlice[T any](list []T) []any
ToInterfaceSlice converts a generic slice to slice of interfaces.
ToUniqueStringSlice
func ToUniqueStringSlice(value any) (result []string)
ToUniqueStringSlice casts `value` to a slice of non-zero unique strings.
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.