Documentation ¶
Index ¶
- func Contains[T comparable](s T, list []T) bool
- func Convert[T any, V any](items []T, converter func(T) V, filter func(T) bool) []V
- func Each[T any](items []T, action func(T))
- func EachE[T any](items []T, action func(T) error) error
- func MakItemMap[T any, K comparable](items []T, namer func(T) K) map[K]T
- func MakeMap[T any, K comparable, V any](items []T, namer func(T) K, mapper func(T, V) V, filter func(T) bool) map[K]V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
func Contains[T comparable](s T, list []T) bool
Contains checks that the string is Contains in the specified list
func Convert ¶
Convert takes a slice of items of type T, a converter function that converts each item from type T to type V, and a filter function that determines whether each item should be included
func Each ¶
func Each[T any](items []T, action func(T))
Each applies the given action function to each item in the items slice. The action function takes one argument of type T and has no return value. Example usage:
Each([]int{1, 2, 3}, func(item int) { fmt.Println(item) })
Another example usage:
Each([]string{"apple", "banana", "cherry"}, func(item string) { fmt.Println(item) })
func EachE ¶
EachE applies the given action function to each item in the items slice. If the action function returns an error for any item, EachE immediately returns that error. Otherwise, it returns nil. It ensures that the action function has the signature func(T) error, where T represents the type of items in the slice.
func MakItemMap ¶
func MakItemMap[T any, K comparable](items []T, namer func(T) K) map[K]T
MakItemMap takes in a slice of items and a namer function, and returns a map that maps the result of the namer function for each item to the item itself.
func MakeMap ¶
func MakeMap[T any, K comparable, V any](items []T, namer func(T) K, mapper func(T, V) V, filter func(T) bool) map[K]V
MakeMap creates a map by iterating through the items and applying the namer, mapper, and picker functions. It returns a map with keys of type K and values of type V. The namer function is used to determine the key for each item. The mapper function is used to compute the value for each key. The current value for the same key is passed as the second argument to the mapper function. The filter function is used to filter the items. Only the items that satisfy the picker function will be included in the result map.
Types ¶
This section is empty.