miscutil

package
v2.9.4 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package miscutil provides an "Island of Misfit Toys", but for helper functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheFunc

func CacheFunc[K comparable, V any](f func(K) V, size int) func(K) V

CacheFunc caches any function with a single input and output. Uses a LRU with the given size. The size defualts to 100 to avoid errors.

func Max

func Max[T constraints.Ordered](a, b T) T

Max returns the larger of a and b.

func Min

func Min[T constraints.Ordered](a, b T) T

Min returns the smaller of a and b.

func ReadInto added in v2.7.0

func ReadInto(dst []byte, r io.Reader) (int, error)

ReadInto reads into dst until the end of the stream. If the stream has more than len(dst) bytes, an io.ErrShortBuffer error is returned.

func WithPipe

func WithPipe(wcb func(w io.Writer) error, rcb func(r io.Reader) error) error

WithPipe calls rcb with a reader and wcb with a writer

Types

type Iterator

type Iterator struct {
	// contains filtered or unexported fields
}

Iterator provides functionality for generic imperative iteration. TODO: Move file set merge and datum merge to this abstraction. TODO: Improve when we upgrade to a go version with generics.

func NewIterator

func NewIterator(ctx context.Context, iterate func(func(interface{}) error) error) *Iterator

NewIterator creates a new iterator. DEPRECATED: use stream.NewFromForEach instead

func (*Iterator) Next

func (i *Iterator) Next() (interface{}, error)

Next returns the next item and progresses the iterator.

type WorkDeduper

type WorkDeduper[K comparable] struct {
	// contains filtered or unexported fields
}

func (*WorkDeduper[K]) Do

func (wd *WorkDeduper[K]) Do(ctx context.Context, k K, cb func() error) error

Concurrent calls to Do will block until cb has been completed by one of them, then the others will run, possibly concurrently. The motivating use case is to eliminate network round trips when populating a cache. Callers should check and populate the cache inside cb.

Jump to

Keyboard shortcuts

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