Documentation
¶
Index ¶
- func Catch[T any](collector *ErrorCollector, callback func() (T, error)) T
- func CatchFn[T any](collector *ErrorCollector, callback func() (T, error)) func() T
- func MapEntriesOrError[K1 comparable, V1 any, K2 comparable, V2 any](in map[K1]V1, iteratee func(key K1, value V1) (K2, V2, error)) (map[K2]V2, error)
- type ErrorCollector
- type IfElse
- type Iteratee
- type IterateeWithError
- type NoIndexIteratee
- type NoIndexIterateeWithError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Catch ¶
func Catch[T any](collector *ErrorCollector, callback func() (T, error)) T
Catch is a utility function that catches an error and collects it in an ErrorCollector.
func CatchFn ¶
func CatchFn[T any](collector *ErrorCollector, callback func() (T, error)) func() T
CatchFn is a utility function that catches an error and collects it in an ErrorCollector. It returns a function that can be called to execute the callback.
func MapEntriesOrError ¶
func MapEntriesOrError[K1 comparable, V1 any, K2 comparable, V2 any](in map[K1]V1, iteratee func(key K1, value V1) (K2, V2, error)) (map[K2]V2, error)
MapEntriesOrError manipulates a map entries and transforms it to a map of another type. If the iteratee function returns an error, the function returns the error.
Types ¶
type ErrorCollector ¶
type ErrorCollector struct {
// contains filtered or unexported fields
}
ErrorCollector is a struct that catches errors and stores them in errors field
func NewErrorCollector ¶
func NewErrorCollector() *ErrorCollector
NewErrorCollector returns an instance of ErrorCollector
func (*ErrorCollector) Collect ¶
func (c *ErrorCollector) Collect(err error) *ErrorCollector
Collect collects error and joins it in the errors field
func (*ErrorCollector) Error ¶
func (c *ErrorCollector) Error() error
Error returns joined errors caught by ErrorCollector
func (*ErrorCollector) OK ¶
func (c *ErrorCollector) OK() bool
OK checks if ErrorCollector didn't catch any errors
type IfElse ¶
type IfElse[T any] interface { Else(result T) T }
IfElse is an interface that satisfies github.com/samber/lo IfF function return value
type Iteratee ¶
Iteratee represents a function that processes an item of type T at a specific index, returning a result of type R. It is useful for operations requiring both the item and its index.
func MapAndCollect ¶
func MapAndCollect[T, R any](catcher *ErrorCollector, iteratee NoIndexIterateeWithError[T, R]) Iteratee[T, R]
MapAndCollect takes ErrorCollector and a function mapper that can return an error. If the mapper function returns an error it is joined to the errors field of ErrorCollector
func MappingFn ¶
func MappingFn[T, R any](mapper NoIndexIteratee[T, R]) Iteratee[T, R]
MappingFn allows to pass a mapper function that doesn't require index to "github.com/samber/lo" Map() function
type IterateeWithError ¶
IterateeWithError represents a function that processes an item of type T at a specific index, returning a result of type R and an error if the operation fails. It is useful for operations that might encounter errors during processing.
func MappingFnWithError ¶
func MappingFnWithError[T, R any](mapper NoIndexIterateeWithError[T, R]) IterateeWithError[T, R]
MappingFnWithError allows to pass a mapper function that doesn't require index and also returns an error "github.com/samber/lo" Map() function
type NoIndexIteratee ¶
type NoIndexIteratee[T, R any] func(item T) R
NoIndexIteratee represents a function that processes an item of type T without requiring its index, returning a result of type R. It is useful for operations where the index is irrelevant.
type NoIndexIterateeWithError ¶
NoIndexIterateeWithError represents a function that processes an item of type T without requiring its index, returning a result of type R and an error if the operation fails. It is useful for operations where the index is irrelevant and error handling is required.