Documentation
¶
Overview ¶
Package fun is a zero-dependency collection of tools and idoms that takes advantage of generics. Iterators, error handling, a native-feeling Set type, and a simple pub-sub framework for distributing messages in fan-out patterns.
Index ¶
- Variables
- func Check(fn func()) (err error)
- func Invariant(cond bool, args ...any)
- func Is[T any](in any) bool
- func IsInvariantViolation(r any) bool
- func Must[T any](arg T, err error) T
- func Safe[T any](fn func() T) (out T, err error)
- func SafeCtx[T any](ctx context.Context, fn func(context.Context) T) (out T, err error)
- func Unwrap[T any](in T) T
- func Wait(ctx context.Context, wg *sync.WaitGroup) bool
- type Iterator
Constants ¶
This section is empty.
Variables ¶
var ErrInvariantViolation = errors.New("invariant violation")
ErrInvariantViolation is the root error of the error object that is the content of all panics produced by the Invariant helper.
Functions ¶
func Check ¶ added in v0.3.0
func Check(fn func()) (err error)
Check, like safe and SafeCtx runs a function without arguments that does not produce an error, and, if the function panics, converts it into an error.
func Invariant ¶ added in v0.3.0
Invariant panics if the condition is false Invariant panics, passing an error that is rooted by ErrInvariantViolation.
func Is ¶
Is a generic version of `errors.Is` that takes advantage of the Unwrap function, and is useful for checking if an object of an interface type is or wraps an implementation of the type parameter.
func IsInvariantViolation ¶ added in v0.3.0
IsInvariantViolation returns true if the argument is or resolves to ErrInvariantViolation.
func Must ¶
Must wraps a function that returns a value and an error, and converts the error to a panic.
func Unwrap ¶
func Unwrap[T any](in T) T
Unwrap is a generic equivalent of the `errors.Unwrap()` function for any type that implements an `Unwrap() T` method. useful in combination with Is.
Types ¶
type Iterator ¶
type Iterator[T any] interface { Next(context.Context) bool Close(context.Context) error Value() T }
Iterator provides a safe, context-respecting iterator paradigm for iterable objects, along with a set of consumer functions and basic implementations.
The itertool package provides a number of tools and paradigms for creating and processing Iterator objects, including Generators, Map and Reduce, Filter as well as Split and Merge to combine or divide iterators.
In general, Iterators cannot be safe for access from multiple concurrent goroutines, because it is impossible to synchronize calls to Next() and Value(); however, itertool.Range() and itertool.Split() provide support for these workloads.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package erc provides a simple/fast error aggregation tool for collecting and aggregating errors.
|
Package erc provides a simple/fast error aggregation tool for collecting and aggregating errors. |
|
Package itertool provides a set of functional helpers for managinging and using fun.Iterator implementations, including a parallel Map/Reduce, Merge, and other convenient tools.
|
Package itertool provides a set of functional helpers for managinging and using fun.Iterator implementations, including a parallel Map/Reduce, Merge, and other convenient tools. |
|
Package pubsub provides a message broker for one-to-many or many-to-many message distribution.
|
Package pubsub provides a message broker for one-to-many or many-to-many message distribution. |
|
Package seq provides single and double linked-list implementations and tools (e.g.
|
Package seq provides single and double linked-list implementations and tools (e.g. |
|
Package Set provides ordered and unordered set implementations for arbitrary comparable types.
|
Package Set provides ordered and unordered set implementations for arbitrary comparable types. |