fun

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2023 License: Apache-2.0 Imports: 3 Imported by: 17

README

fun -- Go Generic Functions and Tools

Go Reference

fun is a simple, well tested, zero-dependency, collection of packages with generic function, tools, patterns, and the kind of thing you could write one-offs for but shouldn't.

Packages:

  • erc (error collecting)
  • itertool (iterator tools)
  • pubsub (message broker and queues)
  • set (generic ordered and unordered sets)

For more information, see the documentation, but of general interest:

  • In itertools and with fun.Iterator, an iterator framework and tools for interacting with iterators and generators.
  • In pubsub, a channel-based message broker (for one-to-many channel patterns), with several backend patterns for dealing with load-shedding and message distribution patterns.
  • In erc, an error collector implementation for threadsafe error aggregation and introspection, particularly in worker-pool, applications.
  • In set, a Set type, with ordered and unordered implementations.
  • Queue and Deque implementations (in pubsub) that provide thread-safe linked-list based implementations and Wait methods to block until new items added.

Contributions welcome, the general goals of the project:

  • superior API ergonomics.
  • great high-level abstractions.
  • obvious and clear implementations.

Have fun!

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Is

func Is[T any](in any) bool

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 Must

func Must[T any](arg T, err error) T

func Safe

func Safe[T any](fn func() T) (out T, err error)

func SafeCtx

func SafeCtx[T any](ctx context.Context, fn func(context.Context) T) (out T, err error)

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.

func Wait

func Wait(ctx context.Context, wg *sync.WaitGroup) bool

Wait returns when the all waiting items are done, *or* the context is canceled. This operation will leak a go routine if the WaitGroup never returns and the context is canceled.

The return value lets you know that there may still be pending work.

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.

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.

Jump to

Keyboard shortcuts

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