lox

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

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

func Unwrap

func Unwrap[T any](value *T) IfElse[T]

Unwrap is a helper function that takes a pointer and returns its unwrapped value if it is not nil

type Iteratee

type Iteratee[T, R any] func(item T, index int) R

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

type IterateeWithError[T, R any] func(item T, index int) (R, error)

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

type NoIndexIterateeWithError[T, R any] func(item T) (R, error)

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.

Jump to

Keyboard shortcuts

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