Documentation
¶
Overview ¶
Package maps provides handy functional programming -style functions that operate on map data types.
Index ¶
- func All[K comparable, V any](pairs map[K]V, f func(K, V) bool) bool
- func Any[K comparable, V any](pairs map[K]V, f func(K, V) bool) bool
- func Count[K comparable, V any](pairs map[K]V, f func(K, V) bool) int
- func HasKey[K comparable, V any](pairs map[K]V) func(k K) bool
- func Key[K comparable, V any](key K, value V) K
- func Keys[K comparable, V any](pairs map[K]V) []K
- func Map[K comparable, V any, T any](pairs map[K]V, f func(K, V) T) []T
- func ProductKeys[K Number, V any](pairs map[K]V) (ret K)
- func ProductValues[K comparable, V Number](pairs map[K]V) (ret V)
- func Reduce[K comparable, V any, T any](pairs map[K]V, acc T, f func(K, V, T) T) T
- func ShallowCopy[K comparable, V any](pairs map[K]V) map[K]V
- func SumKeys[K Number, V any](pairs map[K]V) (ret K)
- func SumValues[K comparable, V Number](pairs map[K]V) (ret V)
- func Swap[K comparable, V comparable](pairs map[K]V) map[V]K
- func Value[K any, V any](key K, value V) V
- func ValueLen[K any, T any](key K, value []T) int
- func Values[K comparable, V any](pairs map[K]V) []V
- type Number
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func All ¶
func All[K comparable, V any](pairs map[K]V, f func(K, V) bool) bool
All returns true if all f(key, value) calls return true.
func Any ¶
func Any[K comparable, V any](pairs map[K]V, f func(K, V) bool) bool
Any returns true if any f(key, value) call returns true.
func Count ¶
func Count[K comparable, V any](pairs map[K]V, f func(K, V) bool) int
Count returns the count of items in the map for which `f(k, v)` returns true.
func HasKey ¶
func HasKey[K comparable, V any](pairs map[K]V) func(k K) bool
HasKey returns a function that tests if a key exists in the map.
func Key ¶
func Key[K comparable, V any](key K, value V) K
Key returns the key of a map key/value pair.
func Map ¶
func Map[K comparable, V any, T any](pairs map[K]V, f func(K, V) T) []T
Map maps the (k,v) pairs to a slice of values.
func ProductKeys ¶
ProductKeys multiples the keys in a map together.
func ProductValues ¶
func ProductValues[K comparable, V Number](pairs map[K]V) (ret V)
ProductValues multiples the values in a map together.
func Reduce ¶
func Reduce[K comparable, V any, T any](pairs map[K]V, acc T, f func(K, V, T) T) T
Reduce reduces a map using an accumulator.
func ShallowCopy ¶
func ShallowCopy[K comparable, V any](pairs map[K]V) map[K]V
ShallowCopy makes a shallow copy (top key/value pairs only) of the given map.
func SumValues ¶
func SumValues[K comparable, V Number](pairs map[K]V) (ret V)
SumValues sums up the values in a map.
func Swap ¶
func Swap[K comparable, V comparable](pairs map[K]V) map[V]K
Swap swaps the keys and values and returns a new map.
func Values ¶
func Values[K comparable, V any](pairs map[K]V) []V
Values returns the values of a map.
Types ¶
type Number ¶
type Number interface { constraints.Integer | constraints.Unsigned | constraints.Float | constraints.Complex }
Number has the "+" operator.