Documentation
¶
Overview ¶
Package devtoolkit provides a collection of utilities for Golang development.
Index ¶
- Variables
- func Contains[T comparable](slice []T, item T) bool
- func ContainsWithPredicate[T any](slice []T, item T, predicate func(T, T) bool) bool
- func Difference[T comparable](slice, other []T) []T
- func Filter[T any](slice []T, predicate func(T) bool) []T
- func FilterNot[T any](slice []T, predicate func(T) bool) []T
- func IndexOf[T comparable](slice []T, item T) int
- func IndexOfWithPredicate[T any](slice []T, item T, predicate func(T, T) bool) int
- func Intersection[T comparable](slice, other []T) []T
- func IsZero(t any) bool
- func LastIndexOf[T comparable](slice []T, item T) int
- func LastIndexOfWithPredicate[T any](slice []T, item T, predicate func(T, T) bool) int
- func LoadPropFile[T any](filePath string, props []T) error
- func Map[T, R any](slice []T, mapper func(T) R) []R
- func Remove[T comparable](slice []T, item T) bool
- func RemoveAll[T comparable](slice []T, item T) bool
- func RemoveAllWithPredicate[T any](slice []T, item T, predicate func(T, T) bool) bool
- func RemoveAt[T any](slice []T, index int) bool
- func RemoveDuplicates[T comparable](slice []T) bool
- func RemoveIf[T any](slice []T, predicate func(T) bool) bool
- func RemoveRange[T any](slice []T, start, end int) bool
- func RemoveWithPredicate[T any](slice []T, item T, predicate func(T, T) bool) bool
- func Reverse[T any](slice []T)
- func ToPtr[T any](t T) *T
- func Union[T comparable](slice, other []T) []T
- type ConcurrentExec
- type ConcurrentExecResponse
- type ConcurrentFn
Constants ¶
This section is empty.
Variables ¶
var ( ConcurrentExecAlreadyRunningErr = errors.New("concurrent fns already running") ConcurrentExecNilContextErr = errors.New("context must not be nil") ConcurrentExecFnsNilOrEmptyErr = errors.New("fns must not be nil or empty") )
Error values that can be returned by ConcurrentExec.
Functions ¶
func Contains ¶
func Contains[T comparable](slice []T, item T) bool
Contains checks if a slice contains an item. Item must be comparable.
func ContainsWithPredicate ¶
ContainsWithPredicate checks if a slice contains an item. Use predicate to compare items.
func Difference ¶
func Difference[T comparable](slice, other []T) []T
Difference returns a new slice containing all items from slice that are not present in other.
func Filter ¶
Filter returns a new slice containing all items from slice for which predicate returns true.
func FilterNot ¶
FilterNot returns a new slice containing all items from slice for which predicate returns false.
func IndexOf ¶
func IndexOf[T comparable](slice []T, item T) int
IndexOf returns the index of the first instance of item in slice, or -1 if item is not present in slice.
func IndexOfWithPredicate ¶
IndexOfWithPredicate returns the index of the first instance of item in slice, or -1 if item is not present in slice. Use predicate to compare items.
func Intersection ¶
func Intersection[T comparable](slice, other []T) []T
Intersection returns a new slice containing all items from slice that are also present in other.
func LastIndexOf ¶
func LastIndexOf[T comparable](slice []T, item T) int
LastIndexOf returns the index of the last instance of item in slice, or -1 if item is not present in slice.
func LastIndexOfWithPredicate ¶
LastIndexOfWithPredicate returns the index of the last instance of item in slice, or -1 if item is not present in slice. Use predicate to compare items.
func LoadPropFile ¶
LoadPropFile loads configuration properties from a file into the provided slice of structs. The file format can be either YAML or JSON. The 'filePath' parameter specifies the path to the configuration file. The 'props' parameter is a slice of pointers to struct instances that should be populated with the loaded properties. Returns an error if the file cannot be loaded, parsed, or is of an unsupported format.
func Map ¶
func Map[T, R any](slice []T, mapper func(T) R) []R
Map returns a new slice containing the results of applying the given mapper function to each item in slice.
func Remove ¶
func Remove[T comparable](slice []T, item T) bool
Remove removes the first instance of item from slice, if present. Returns true if item was removed, false otherwise.
func RemoveAll ¶
func RemoveAll[T comparable](slice []T, item T) bool
RemoveAll removes all instances of item from slice, if present. Returns true if item was removed, false otherwise.
func RemoveAllWithPredicate ¶
RemoveAllWithPredicate removes all instances of item from slice, if present. Use predicate to compare items. Returns true if item was removed, false otherwise.
func RemoveAt ¶
RemoveAt removes the item at the given index from slice. Returns true if item was removed, false otherwise.
func RemoveDuplicates ¶
func RemoveDuplicates[T comparable](slice []T) bool
RemoveDuplicates removes all duplicate items from slice. Returns true if items were removed, false otherwise.
func RemoveIf ¶
RemoveIf removes all items from slice for which predicate returns true. Returns true if items were removed, false otherwise.
func RemoveRange ¶
RemoveRange removes the items in the given range from slice. Returns true if items were removed, false otherwise.
func RemoveWithPredicate ¶
RemoveWithPredicate removes the first instance of item from slice, if present. Use predicate to compare items. Returns true if item was removed, false otherwise.
func Union ¶
func Union[T comparable](slice, other []T) []T
Union returns a new slice containing all items from slice and other.
Types ¶
type ConcurrentExec ¶
type ConcurrentExec struct {
// contains filtered or unexported fields
}
ConcurrentExec allows to execute a slice of ConcurrentFn concurrently. The running state, results, errors and context for the concurrent execution are stored within the struct.
func (*ConcurrentExec) CancelExecution ¶
func (ce *ConcurrentExec) CancelExecution()
func (*ConcurrentExec) Done ¶
func (ce *ConcurrentExec) Done() <-chan struct{}
func (*ConcurrentExec) Errors ¶
func (ce *ConcurrentExec) Errors() []error
func (*ConcurrentExec) ExecuteFns ¶
func (ce *ConcurrentExec) ExecuteFns(ctx context.Context, fns ...ConcurrentFn) (ConcurrentExecResponse, error)
ExecuteFns receives a context and a slice of functions to execute concurrently. It returns a ConcurrentExecResponse interface and an error if execution could not be started.
func (*ConcurrentExec) Results ¶
func (ce *ConcurrentExec) Results() []any
type ConcurrentExecResponse ¶
type ConcurrentExecResponse interface { // Results blocks until all functions are done and returns the results. Results() []any // blocks until all fns are done // Errors blocks until all functions are done and returns any errors that occurred. Errors() []error // blocks until all fns are done // CancelExecution cancels the execution of all functions. CancelExecution() // cancels the execution of all fns // Done returns a channel that is closed when all functions are done. Done() <-chan struct{} // returns a channel that is closed when all fns are done }
ConcurrentExecResponse is the interface returned by ExecuteFns to interact with the results of the concurrent execution.