Documentation
¶
Overview ¶
Package gen is a generic general use Go functions library which can be used throughout any project.
As a rule the methods in this package are non-destructive and return a new value rather than modifying the original.
Index ¶
- func As[T any](in ...T) []T
- func Close[U channel[T], T any](in ...U)
- func Compare[T comparable](a, b []T) error
- func Diff[T comparable](a, b []T) []T
- func Equal[T comparable](a, b []T) bool
- func Exclude[T comparable](a []T, b ...T) []T
- func Has[T comparable](in []T, v T) bool
- func Index[T comparable](in []T, v T) int
- func Indices[T comparable](in []T, v T) []int
- func Intersect[T comparable](a, b []T) []T
- func Match[T comparable](a, b []T) bool
- func ReadOnly[U chan T, T any](in ...U) []<-chan T
- func Unique[U ~[]T, T comparable](in U) []T
- func WriteOnly[U chan T, T any](in ...U) []chan<- T
- type FMap
- type IndexMismatchError
- type LengthMismatchError
- type Map
- type Slice
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func As ¶
func As[T any](in ...T) []T
As allows you to cast N values passed in through a variadic argument to a slice of N values. This is useful for casting disparate struct types to slices of implemented interfaces
Example: As[io.Reader](&bytes.Buffer{}, &bufio.Reader{})
func Close ¶
func Close[U channel[T], T any](in ...U)
Close closes all channels in the input slice
NOTE: If a channel is already closed any panic will be ignored and the channel will be skipped
func Compare ¶
func Compare[T comparable](a, b []T) error
Compare returns nil if the two input slices are equal otherwise it returns an error indicating the issue
func Diff ¶
func Diff[T comparable](a, b []T) []T
Diff returns the symmetric difference between the two input slices
func Equal ¶
func Equal[T comparable](a, b []T) bool
Equal returns true if the two input slices are exactly equal
func Exclude ¶
func Exclude[T comparable](a []T, b ...T) []T
Exclude returns a slice of values from the input slice minus the values supplied in the second argument
func Has ¶
func Has[T comparable](in []T, v T) bool
Has determines if the input slice contains the input value
func Index ¶
func Index[T comparable](in []T, v T) int
Index returns the index of the first occurrence of the input value
func Indices ¶
func Indices[T comparable](in []T, v T) []int
Indices returns a slice of indices for all occurrences of value `v`
func Intersect ¶
func Intersect[T comparable](a, b []T) []T
Intersect returns the intersection between the two input slices
func Match ¶
func Match[T comparable](a, b []T) bool
Match returns true if the two input slices contain equivalent values NOTE: Match ignores ordering
func ReadOnly ¶
func ReadOnly[U chan T, T any](in ...U) []<-chan T
ReadOnly accepts a slice of channels and returns a slice of channels that are read-only.
func Unique ¶
func Unique[U ~[]T, T comparable](in U) []T
Unique returns a slice of unique values from the input slice
Types ¶
type FMap ¶
type FMap[K, V comparable] Map[K, V]
FMap is a flippale map where the key and value can be swapped
type IndexMismatchError ¶ added in v1.2.0
func (IndexMismatchError[T]) Error ¶ added in v1.2.0
func (e IndexMismatchError[T]) Error() string
type LengthMismatchError ¶ added in v1.2.0
func (LengthMismatchError) Error ¶ added in v1.2.0
func (e LengthMismatchError) Error() string
type Map ¶
type Map[K comparable, V any] map[K]V
Map wraps the Go map type in a generic which provides helper functions for accessing slices of keys or values without repeating the the implementation for each type
type Slice ¶
type Slice[T comparable] []T
Slice wraps a slice of values with helper functions