generics

package
v0.0.0-...-cc2f144 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2024 License: MIT Imports: 0 Imported by: 0

Documentation

Index

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

func Convert[T any, V any](items []T, converter func(T) V, filter func(T) bool) []V

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

func EachE[T any](items []T, action func(T) error) error

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.

Jump to

Keyboard shortcuts

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