Documentation
¶
Overview ¶
Package generic provides a set of type agnostic helpers.
Index ¶
- func ApplyOptions[OT OptionFunc[T], T any](settings *T, options ...OT) error
- func CloneSlice[T any](slice []T) []T
- func CompactSlice[T any](slice []T) []T
- func DrainBuffer[T any](ch <-chan T)
- func Max[T constraints.Ordered](x, y T) T
- func Min[T constraints.Ordered](x, y T) T
- func ParseEnum[e Enum](start, end e, s string) (e, error)
- type Closer
- type ConstError
- type Enum
- type OptionFunc
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.
Types ¶
type ConstError ¶
type ConstError string
func (ConstError) Error ¶
func (errStr ConstError) Error() string
type OptionFunc ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.