fun is a simple, well-tested, zero-dependency "Core Library" for
Go. Think of it as a collection of the best parts of the utils
package or shared or common packages in any given Go application,
but with solid design, highly ergonomic interfaces, and thorough
testing.
fun aims to be easy to adopt: the interfaces (and implementations!)
are simple and (hopefully!) easy to use. There are no external
dependencies and all of the code is well-tested. You can (and
should!) always adopt the tools that make the most sense to use for
your project.
-
Every iterator tool you always wish you had in the
irt(ha!) package. Easily create, manipulate, and transform iterators, and avoid writing (and rewriting,) basic logic again and again. -
Error tools.
erc.Collectoris an error aggregator safe for concurrent access, with methods to collect errors conditionally (for validation), and annotating errors. Theerscollection has a string-derived error typeers.Errorso that you can haveconsterrors. -
A set of worker pools helpers and tools in the
wpapackage for both ephemeral workloads as well as long-running pipelines. Particularly powerful in combination with the data types, iterator tools, and pubsub tooling. -
Powerful synchronization and atomic primitives, updated for the era of generics in
adt:-
adt.Map[K,V]means now you can usesync.Mapwithout (terrifying) type casts everywhere. -
adt.Pool[T]provides a type-safesync.Poolwith cleanup and constructor hooks. -
adt.Atomic[T]is an atomic value container, that you can use to avoid littering your code with mutexes. (n.b. you can store mutable atomic values inadt.Atomic[T]which are (of course) not safe for concurrent use, which is a bit of a gotcha, but for thisadt.Locked[T]steps in to handle the mutex for you. -
adt.Once[T]means you can getsync.OnceFunc, and friends, but as a type that you can add as a field to your on types for mutexes that you don't have to manage yourself. -
within
adt,shard.Map[K,V]provides a write-optimized, fully versioned map implementation that divides the keyspace among a number of constituent maps (shards) to reduce mutex contention for certain workloads.
-
-
Delightful data types you always wish you had, in the
dtpackage:- a ring buffer (
dt.Ring[T]) - single and doubly linked lists (
dt.Stack[T]anddt.List[T]) - sets (
dt.Set[K]anddt.OrderedSet[T]) - an ordered map
dt.OrderedMap[K,V](also thread safe, and accessible viaadt.) - histograms (in
dt/hdrhist) - wrappers of standard library (stw)things (maps, slices, pointers,) for ergonomic takes on Go constructs.
- an "optional" wrapper (
dt.Optional[T]) so you can avoid overloading pointer values in your type definitions.
- a ring buffer (
-
A collection of function object tools, wrappers and tools for common function type in
fn(without contexts) andfnx(with contexts). -
Higher order pubsub tools, notably threadsafe queue and deque implementations--
pubsub.Queue[T]andpubsub.Deque[T]which avoid channels entirely, and have support for unlimited, fixed-buffered, and burstable limits. Also a one-to-many or a many-to-many message broker, so you can have a "broadcast channel." -
Service orchestration.
srv.Servicehandles the lifecycle of "background" processes inside of an application. You can now start services like HTTP servers, background monitoring and workloads, and sub-processes, and ensure that they exit cleanly (at the right time!) and that their errors propagate clearly back to the "main" thread. -
Lightweight test infrastructure:
assertandcheck(testify-style assertions, but with generics,) testing tools and helpers intestt(testy!), and a fluent-style interface withensure.
There are no plans for a 1.0 release, though major backward-breaking changes increment the second (major) release value, and limited maintenance releases are possible/considered to maintain compatibility.
v0.14.0: go1.24 and greater. Re-focus API; newirtandwpapackages. Move all code out of the root package. (current)v0.13.0: go1.24 and greater. Reorganization of function API, and a bridge to the next major release. (experimental)v0.12.0: go1.24 and greater. Major API impacting release. (maintained)v0.11.0: go1.23 and greater.v0.10.0: go1.20 and greater.v0.9.0: go1.19 and greater.
There may be small changes to exported APIs within a release series, although, major API changes will increment the major release value.
Contributions welcome, the general goals of the project:
- superior API ergonomics.
- great high-level abstractions.
- obvious and clear implementations.
- no external dependencies.
Please feel free to open issues or file pull requests.
Have fun!