Documentation
¶
Index ¶
- Variables
- func Abs[T Signed](value T) T
- func All[T any](slice []T, fn func(T) bool) bool
- func Any[T any](slice []T, fn func(T) bool) bool
- func AsMap[K comparable, V any](slice Items[K, V]) map[K]V
- func Average[T Numeric](args ...T) T
- func Clamp[T Orderable](value, min, max T) T
- func CopyMap[K comparable, V any](mp map[K]V) map[K]V
- func CopySlice[T any](slice []T) []T
- func EqualApprox[T Numeric](lhs, rhs, delta T) bool
- func EqualsMap[K, V comparable](a, b map[K]V) bool
- func EqualsSlice[T comparable](a, b []T) bool
- func EqualsSlice2[T comparable](a, b [][]T) bool
- func Filter[T any](slice []T, fn func(T) bool) []T
- func FilterMap[K comparable, V any](mp map[K]V, fn func(K, V) bool) map[K]V
- func If[T any](cond bool, trueVal, falseVal T) T
- func Map[A any, B any](slice []A, fn func(A) B) []B
- func MapRange[T Numeric](value, inMin, inMax, outMin, outMax T) T
- func Max[T Orderable](args ...T) T
- func Min[T Orderable](args ...T) T
- func Partition[T any](slice []T, fn func(T) bool) (match []T, rest []T)
- func Reverse[T any](slice []T) []T
- func ReverseInPlace[T any](slice []T)
- func Sort[T Orderable](slice []T)
- func SortBy[T any, K Orderable](slice []T, fn func(T) K)
- func SortFunc[T any](slice []T, less func(a, b T) bool)
- func Sorted[T Orderable](slice []T) []T
- func SortedBy[T any, K Orderable](slice []T, fn func(T) K) []T
- func SortedFunc[T any](slice []T, less func(a, b T) bool) []T
- func Sum[T Orderable](args ...T) T
- func Unique[T comparable](slice []T) []T
- func UniqueBy[K comparable, T any](slice []T, fn func(T) K) []T
- func Zip[T any](args ...[]T) [][]T
- type Item
- type Items
- type Iterator
- type Numeric
- type Once
- type Orderable
- type OrderedMap
- func (om *OrderedMap[K, V]) AsList() *OrderedMap[K, V]
- func (om *OrderedMap[K, V]) Delete(key K) V
- func (om *OrderedMap[K, V]) Exists(key K) bool
- func (om *OrderedMap[K, V]) Get(key K) V
- func (om *OrderedMap[K, V]) GetOk(key K) (V, bool)
- func (om *OrderedMap[K, V]) GetOr(key K, default_ V) V
- func (om *OrderedMap[K, V]) Iter(fn func(K, V))
- func (om *OrderedMap[K, V]) IterBreak(fn func(K, V) bool)
- func (om *OrderedMap[K, V]) Keys() []K
- func (om *OrderedMap[K, V]) Len() int
- func (om *OrderedMap[K, V]) MarshalJSON() ([]byte, error)
- func (om *OrderedMap[K, V]) Set(key K, value V)
- func (om *OrderedMap[K, V]) SortKeys(less func(a, b K) bool)
- func (om *OrderedMap[K, V]) String() string
- func (om *OrderedMap[K, V]) ToMap() map[K]V
- func (om *OrderedMap[K, V]) UnmarshalJSON(b []byte) error
- func (om *OrderedMap[K, V]) Values() []V
- type Signed
- type Stack
- type Unsigned
- type Zipped
Constants ¶
This section is empty.
Variables ¶
var ErrUnmarshalError = errors.New("unmarshal error")
Functions ¶
func All ¶
All checks if a given function fn returns true for all elements in the slice slice of type T.
func Any ¶
Any checks if a given function fn returns true for at least one element in the slice slice of type T.
func AsMap ¶
func AsMap[K comparable, V any](slice Items[K, V]) map[K]V
func Average ¶
func Average[T Numeric](args ...T) T
Average calculates the average value of the arguments.
This function will round implicitly with integer types.
func Clamp ¶
func Clamp[T Orderable](value, min, max T) T
Clamp restricts a value to be within the range [min, max].
func CopyMap ¶
func CopyMap[K comparable, V any](mp map[K]V) map[K]V
func EqualApprox ¶
func EqualsMap ¶
func EqualsMap[K, V comparable](a, b map[K]V) bool
func EqualsSlice ¶
func EqualsSlice[T comparable](a, b []T) bool
func EqualsSlice2 ¶
func EqualsSlice2[T comparable](a, b [][]T) bool
func FilterMap ¶
func FilterMap[K comparable, V any](mp map[K]V, fn func(K, V) bool) map[K]V
func If ¶
If evaluates a condition and returns either the trueVal or falseVal based on the condition.
func MapRange ¶
func MapRange[T Numeric](value, inMin, inMax, outMin, outMax T) T
MapRange linearly maps a value from the range [inMin, inMax] to the range [outMin, outMax].
func ReverseInPlace ¶
func ReverseInPlace[T any](slice []T)
func SortedFunc ¶
func Unique ¶
func Unique[T comparable](slice []T) []T
func UniqueBy ¶
func UniqueBy[K comparable, T any](slice []T, fn func(T) K) []T
Types ¶
type Item ¶
type Item[K comparable, V any] struct { Key K Value V }
type Items ¶
type Items[K comparable, V any] []Item[K, V]
func AsItems ¶
func AsItems[K comparable, V any](mp map[K]V) Items[K, V]
type Iterator ¶
func NewIterator ¶
type Once ¶
type Once[K comparable] struct { Keys []K }
type OrderedMap ¶
type OrderedMap[K comparable, V any] struct { // contains filtered or unexported fields }
func NewOrderedMap ¶
func NewOrderedMap[K comparable, V any]() *OrderedMap[K, V]
New empty OrderedMap
func NewOrderedMapFromSorted ¶
func NewOrderedMapFromSorted[K Orderable, V any](mp map[K]V) *OrderedMap[K, V]
New OrderedMap from regular map, with keys sorted
func (*OrderedMap[K, V]) AsList ¶
func (om *OrderedMap[K, V]) AsList() *OrderedMap[K, V]
Mark OrderedMap to be encoded as a list of lists when marshaled as JSON
func (*OrderedMap[K, V]) Exists ¶
func (om *OrderedMap[K, V]) Exists(key K) bool
Check if given key exists in map
func (*OrderedMap[K, V]) GetOk ¶
func (om *OrderedMap[K, V]) GetOk(key K) (V, bool)
Get value in map by key with ok
func (*OrderedMap[K, V]) GetOr ¶
func (om *OrderedMap[K, V]) GetOr(key K, default_ V) V
Get value in map by key or default
func (*OrderedMap[K, V]) Iter ¶
func (om *OrderedMap[K, V]) Iter(fn func(K, V))
Iterate over OrderedMap with function
func (*OrderedMap[K, V]) IterBreak ¶
func (om *OrderedMap[K, V]) IterBreak(fn func(K, V) bool)
Iterate over OrderedMap with function that can break at any point
Return false to break, true to continue
func (*OrderedMap[K, V]) MarshalJSON ¶
func (om *OrderedMap[K, V]) MarshalJSON() ([]byte, error)
func (*OrderedMap[K, V]) Set ¶
func (om *OrderedMap[K, V]) Set(key K, value V)
Set value in OrderedMap
func (*OrderedMap[K, V]) SortKeys ¶
func (om *OrderedMap[K, V]) SortKeys(less func(a, b K) bool)
Sort OrderedMap keys by given less function
func (*OrderedMap[K, V]) String ¶
func (om *OrderedMap[K, V]) String() string
Get string representation of OrderedMap
ordered-map[key1: val1, key2: val2]
func (*OrderedMap[K, V]) ToMap ¶
func (om *OrderedMap[K, V]) ToMap() map[K]V
Convert to regular unordered map
func (*OrderedMap[K, V]) UnmarshalJSON ¶
func (om *OrderedMap[K, V]) UnmarshalJSON(b []byte) error