generic

package
v0.0.0-...-604993b Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2023 License: ISC Imports: 3 Imported by: 0

Documentation

Overview

Package generic provides a set of type agnostic helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyOptions

func ApplyOptions[
	OT OptionFunc[T],
	T any,
](settings *T, options ...OT,
) error

func CloneSlice

func CloneSlice[T any](slice []T) []T

CloneSlice is analogous to slices.Clone except that is uses `copy` instead of `append`. I.e. the cloned slices has cap == len(slice).

func CompactSlice

func CompactSlice[T any](slice []T) []T

CompactSlice will return either the input slice, or a copy of it with a cap == len(slice).

func DrainBuffer

func DrainBuffer[T any](ch <-chan T)

DrainBuffer removes any values from the buffered channel. If an unbuffered channel is passed, DrainBuffer panics. It is the callers responsibility to assure that the channel is not in use while draining.

func Max

func Max[T constraints.Ordered](x, y T) T

TODO: is this in the standard somewhere yet?

func Min

func Min[T constraints.Ordered](x, y T) T

TODO: is this in the standard somewhere yet?

func ParseEnum

func ParseEnum[e Enum](start, end e, s string) (e, error)

Types

type Closer

type Closer func() error

Closer wraps a close function to satisfy io.Closer.

func (Closer) Close

func (close Closer) Close() error

type ConstError

type ConstError string

func (ConstError) Error

func (errStr ConstError) Error() string

type Enum

type Enum interface {
	constraints.Integer
	fmt.Stringer
}

type OptionFunc

type OptionFunc[T any] interface {
	~func(*T) error
}

Jump to

Keyboard shortcuts

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