Documentation
¶
Index ¶
- func ErrorHandler[T any](eh Handler[error]) func(T, error) T
- type Converter
- func (cf Converter[I, O]) Convert(in I) O
- func (cf Converter[I, O]) If(cond bool) Converter[I, O]
- func (cf Converter[I, O]) Iterator(seq iter.Seq[I]) iter.Seq[O]
- func (cf Converter[I, O]) Lock() Converter[I, O]
- func (cf Converter[I, O]) PostFilter(f Filter[O]) Converter[I, O]
- func (cf Converter[I, O]) PostHook(h func()) Converter[I, O]
- func (cf Converter[I, O]) PreFilter(f Filter[I]) Converter[I, O]
- func (cf Converter[I, O]) PreHook(h func()) Converter[I, O]
- func (cf Converter[I, O]) When(c func() bool) Converter[I, O]
- func (cf Converter[I, O]) WithContext() func(context.Context, I) (O, error)
- func (cf Converter[I, O]) WithLock(m *sync.Mutex) Converter[I, O]
- func (cf Converter[I, O]) WithLocker(m sync.Locker) Converter[I, O]
- type Filter
- func (fl Filter[T]) Apply(v T) T
- func (fl Filter[T]) If(cond bool) Filter[T]
- func (fl Filter[T]) Join(fls ...Filter[T]) Filter[T]
- func (fl Filter[T]) Lock() Filter[T]
- func (fl Filter[T]) PostHook(op func()) Filter[T]
- func (fl Filter[T]) PreHook(op func()) Filter[T]
- func (fl Filter[T]) Ptr(v *T)
- func (fl Filter[T]) WithLock(mu *sync.Mutex) Filter[T]
- func (fl Filter[T]) WithNext(next Filter[T]) Filter[T]
- type Future
- func (f Future[T]) If(cond bool) Future[T]
- func (f Future[T]) Ignore() func()
- func (f Future[T]) Join(merge func(T, T) T, ops ...Future[T]) Future[T]
- func (f Future[T]) Limit(in int) Future[T]
- func (f Future[T]) Lock() Future[T]
- func (f Future[T]) Once() Future[T]
- func (f Future[T]) PostHook(fn func()) Future[T]
- func (f Future[T]) PreHook(fn func()) Future[T]
- func (f Future[T]) RecoverPanic() (out T, err error)
- func (f Future[T]) Reduce(merge func(T, T) T, next Future[T]) Future[T]
- func (f Future[T]) Resolve() T
- func (f Future[T]) Slice() func() []T
- func (f Future[T]) TTL(dur time.Duration) Future[T]
- func (f Future[T]) When(c func() bool) Future[T]
- func (f Future[T]) WithLock(m *sync.Mutex) Future[T]
- func (f Future[T]) WithLocker(m sync.Locker) Future[T]
- type Handler
- func (of Handler[T]) All(in ...T)
- func (of Handler[T]) Filter(filter func(T) T) Handler[T]
- func (of Handler[T]) If(cond bool) Handler[T]
- func (pf Handler[T]) Job(in T) func(context.Context) error
- func (of Handler[T]) Join(chain ...Handler[T]) Handler[T]
- func (of Handler[T]) Lock() Handler[T]
- func (of Handler[T]) Once() Handler[T]
- func (of Handler[T]) PreHook(prev Handler[T]) Handler[T]
- func (of Handler[T]) Read(in T)
- func (of Handler[T]) RecoverPanic(in T) (err error)
- func (of Handler[T]) Skip(hook func(T) bool) Handler[T]
- func (of Handler[T]) When(cond func() bool) Handler[T]
- func (of Handler[T]) WithLock(mtx *sync.Mutex) Handler[T]
- func (of Handler[T]) WithLocker(mtx sync.Locker) Handler[T]
- func (of Handler[T]) WithNext(next Handler[T]) Handler[T]
- func (of Handler[T]) WithRecover(oe Handler[error]) Handler[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Converter ¶ added in v0.13.0
type Converter[I, O any] func(I) O
Converter describes a function that takes a value of one type and returns a value of another type. provides a simplified version of the fun.Converter type (without contexts or errors). The Converter type provides a number of higher level operation over the function types with the provided methods.
func MakeConverter ¶ added in v0.13.0
MakeConverter creates a new Converter from a function that transforms input type I to output type O.
func (Converter[I, O]) Convert ¶ added in v0.13.0
func (cf Converter[I, O]) Convert(in I) O
Convert applies the converter function to the input value and returns the converted output. This is no different than running the converter directly.
func (Converter[I, O]) If ¶ added in v0.13.0
If returns a converter that executes only when the condition is true, otherwise is a noop and returns zero value of the output type..
func (Converter[I, O]) Iterator ¶ added in v0.14.0
Iterator returns an iterator that yields converted values from the input iterator into the output type. This is an equivalent operation to `irt.Convert`.
func (Converter[I, O]) Lock ¶ added in v0.13.0
Lock returns a converter that protects the execution of the conversion with a new mutex, ensuring that only one conversion runs at a time.
func (Converter[I, O]) PostFilter ¶ added in v0.13.0
PostFilter returns a converter that applies the provided filter to the output after executing the conversion.
func (Converter[I, O]) PostHook ¶ added in v0.13.0
PostHook returns a converter that executes the provided hook function after the conversion using defer, ensuring that the hook always runs. Nil hook functions are ignored.
func (Converter[I, O]) PreFilter ¶ added in v0.13.0
PreFilter returns a converter that applies the provided filter to the input before executing the conversion.
func (Converter[I, O]) PreHook ¶ added in v0.13.0
PreHook returns a converter that executes the provided hook function before the conversion.
func (Converter[I, O]) When ¶ added in v0.13.0
When returns a converter that executes only when the provided condition function returns true.
func (Converter[I, O]) WithContext ¶ added in v0.13.1
WithContext returns a wrapped version of the converter function that has he same signature as fnx.Converter functions.
type Filter ¶ added in v0.13.0
Filter describes a common function object and provides higher level operations on the functions themselves. These functions take an object and returns a value of the same type. This is a special case of the Converter type.
func MakeFilter ¶ added in v0.13.0
MakeFilter creates a new Filter from a function that transforms a value of type T to another value of the same type.
func (Filter[T]) Apply ¶ added in v0.13.0
func (fl Filter[T]) Apply(v T) T
Apply executes the filter function on the provided value and returns the filtered result.
func (Filter[T]) If ¶ added in v0.13.0
If returns a filter that only executes when the condition is true, otherwise the filter will return the input as is.
func (Filter[T]) Join ¶ added in v0.13.0
Join returns a filter that applies this filter followed by all the provided filters in order. Nil filters cause panics.
func (Filter[T]) Lock ¶ added in v0.13.0
Lock returns a filter that executes the filter operation using a new mutex, ensuring only one instance of the filter runs at a time.
func (Filter[T]) PostHook ¶ added in v0.13.0
PostHook returns a filter that executes the provided hook function after applying the filter.
func (Filter[T]) PreHook ¶ added in v0.13.0
PreHook returns a filter that executes the provided hook function before applying the filter.
func (Filter[T]) Ptr ¶ added in v0.13.0
func (fl Filter[T]) Ptr(v *T)
Ptr applies the filter to the value pointed to by the pointer, modifying it in place.
type Future ¶
type Future[T any] func() T
Future is a basic function for providing a fun-style function type for a function object that will produce an object of the specified type.
func AsFuture ¶
AsFuture wraps a value and returns a future object that, when called, will return the provided value.
func MakeFuture ¶
MakeFuture constructs a Future[T] object from a function object.
func (Future[T]) If ¶
If produces a future that only runs when the condition value is true. If the condition is false, the future will return the zero value of T.
func (Future[T]) Ignore ¶
func (f Future[T]) Ignore() func()
Ignore produces a function that will call the Future but discards the output.
func (Future[T]) Join ¶
Join iteratively merges a collection of future operations.
If any of the futures are nil, the zero value for T is used. The merge function MUST NOT be nil.
func (Future[T]) Limit ¶
Limit returns a future that will call the inner future exactly the specified number of times, and return the last value provided thereafter.
func (Future[T]) Lock ¶
Lock returns a wrapped future that ensure that all calls to the future are protected by a mutex.
func (Future[T]) Once ¶
Once returns a future that will only run the underlying future exactly once.
func (Future[T]) PostHook ¶
PostHook unconditionally runs the provided function after running the future. The hook runs in a defer statement.
func (Future[T]) PreHook ¶
PreHook unconditionally runs the provided function before running and returning the function.
func (Future[T]) RecoverPanic ¶
RecoverPanic resolves the future, catching any panics and converting them to errors.
func (Future[T]) Reduce ¶
Reduce takes the input future, the next future, and merges the results using the merge function.
func (Future[T]) Resolve ¶
func (f Future[T]) Resolve() T
Resolve executes the future and returns its value.
func (Future[T]) Slice ¶
func (f Future[T]) Slice() func() []T
Slice returns a future-like function that wraps the output of the future as the first element in a slice.
func (Future[T]) TTL ¶
TTL returns a future that will cache (and return) the value returned by the inner future, for the period described by the value of dur.
func (Future[T]) When ¶
When produces a new future wrapping the input future that executes when the condition function returns true, returning the zero value for T when the condition is false. The condition value is checked every time the future is called.
type Handler ¶
type Handler[T any] func(T)
Handler describes a function that operates on a single object, but returns no output, and is used primarily for side effects, particularly around handling errors or collecting metrics. The Handler implementation here makes it possible to provide panic-safety for these kinds of functions or easily convert to other related types.
func JoinHandlers ¶
JoinHandlers returns a function that combines a collection of handlers.
func NewHandler ¶
NewHandler produces an Handler[T] function as a helper.
func NewNoopHandler ¶ added in v0.13.0
NewNoopHandler creates a handler function that performs no action.
func (Handler[T]) All ¶
func (of Handler[T]) All(in ...T)
All processes all inputs with the specified handler.
func (Handler[T]) Filter ¶
Filter creates an handler that only executes the root handler Use this to process or transform the input before it is passed to the underlying handler. Use in combination with the Skip function to filter out non-actionable inputs.
func (Handler[T]) If ¶
If returns an handler that only executes the root handler if the condition is true.
func (Handler[T]) Job ¶ added in v0.14.0
Job converts a Handler into a panic-safe worker function suitable for use in worker pool implementations (e.g., wpa.RunWithPool). The returned function catches any panics that occur during execution and converts them to errors.
func (Handler[T]) Lock ¶
Lock returns an handler that is protected by a mutex. All execution's of the handler are isolated.
func (Handler[T]) Once ¶
Once produces an handler function that runs exactly once, and successive executions of the handler are noops.
func (Handler[T]) PreHook ¶
PreHook provides the inverse operation to Join, running "prev" handler before the base handler.
Returns itself if prev is nil.
func (Handler[T]) Read ¶ added in v0.13.0
func (of Handler[T]) Read(in T)
Read provides a more expository operation to call a handler function.
func (Handler[T]) RecoverPanic ¶
RecoverPanic runs the handler function with a panic handler and converts a possible panic to an error.
func (Handler[T]) Skip ¶
Skip runs a check before passing the object to the obsever, when the condition function--which can inspect the input object--returns true, the underlying Handler is called, otherwise, the observation is a noop.
func (Handler[T]) When ¶
When returns an handler function that only executes the handler function if the condition function returns true. The condition function is run every time the handler function runs.
func (Handler[T]) WithLocker ¶
WithLocker protects the action of the handler with the provied mutex.