Documentation
¶
Overview ¶
Package maps defines various useful functions with maps of comparable keys and any values.
Index ¶
- func Clear[M ~map[K]V, K comparable, V any](m M)
- func Clone[M ~map[K]V, K comparable, V any](m M) M
- func Copy[M1 ~map[K]V, M2 ~map[K]V, K comparable, V any](dst M1, src M2)
- func DeleteFunc[M ~map[K]V, K comparable, V any](m M, del func(K, V) bool)
- func Equal[M1, M2 ~map[K]V, K, V comparable](m1 M1, m2 M2) bool
- func EqualFunc[M1 ~map[K]V1, M2 ~map[K]V2, K comparable, V1, V2 any](m1 M1, m2 M2, eq func(V1, V2) bool) bool
- func Every[M ~map[K]V, K comparable, V any](m M, callbackFn func(K, V) bool) bool
- func Filter[M ~map[K]V, K comparable, V any](m M, callbackFn func(K, V) bool) (filtered M)
- func ForEach[M ~map[K]V, K comparable, V any](m M, callbackFn func(K, V))
- func IsEmpty[M ~map[K]V, K comparable, V any](m M) bool
- func Keys[M ~map[K]V, K comparable, V any](m M) []K
- func MapFunc[M ~map[K]V, K comparable, V any, W any](m M, callbackFn func(K, V) W) (mapped map[K]W)
- func Reduce[M ~map[K]V, K comparable, V any, I any](m M, callbackFn func(I, K, V) I, initialValue I) I
- func Size[M ~map[K]V, K comparable, V any](m M) int
- func Some[M ~map[K]V, K comparable, V any](m M, callbackFn func(K, V) bool) bool
- func Values[M ~map[K]V, K comparable, V any](m M) []V
- type Map
- func (m *Map[K, V]) Clear()
- func (m Map[K, V]) Clone() Map[K, V]
- func (m Map[K, V]) EqualFunc(m2 Map[K, V], eq func(V, V) bool) bool
- func (m Map[K, V]) Every(callbackFn func(K, V) bool) bool
- func (m Map[K, V]) Filter(callbackFn func(K, V) bool) Map[K, V]
- func (m Map[K, V]) ForEach(callbackFn func(K, V))
- func (m Map[K, V]) IsEmpty() bool
- func (m Map[K, V]) Keys() []K
- func (m Map[K, V]) Size() int
- func (m Map[K, V]) Some(callbackFn func(K, V) bool) bool
- func (m Map[K, V]) Values() []V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clear ¶
func Clear[M ~map[K]V, K comparable, V any](m M)
Clear removes all entries from m, leaving it empty.
func Clone ¶
func Clone[M ~map[K]V, K comparable, V any](m M) M
Clone returns a copy of m. This is a shallow clone: the new keys and values are set using ordinary assignment.
func Copy ¶
func Copy[M1 ~map[K]V, M2 ~map[K]V, K comparable, V any](dst M1, src M2)
Copy copies all key/value pairs in src adding them to dst. When a key in src is already present in dst, the value in dst will be overwritten by the value associated with the key in src.
func DeleteFunc ¶
func DeleteFunc[M ~map[K]V, K comparable, V any](m M, del func(K, V) bool)
DeleteFunc deletes any key/value pairs from m for which del returns true.
func Equal ¶
func Equal[M1, M2 ~map[K]V, K, V comparable](m1 M1, m2 M2) bool
Equal reports whether two maps contain the same key/value pairs. Values are compared using ==.
func EqualFunc ¶
func EqualFunc[M1 ~map[K]V1, M2 ~map[K]V2, K comparable, V1, V2 any](m1 M1, m2 M2, eq func(V1, V2) bool) bool
EqualFunc is like Equal, but compares values using eq. Keys are still compared with ==.
func Every ¶
func Every[M ~map[K]V, K comparable, V any](m M, callbackFn func(K, V) bool) bool
Every returns true if all key-value pairs in the map cause the callback function to return true.
func Filter ¶
func Filter[M ~map[K]V, K comparable, V any](m M, callbackFn func(K, V) bool) (filtered M)
Filter returns a new map containing only the key-value pairs for which the callback function returns true.
func ForEach ¶
func ForEach[M ~map[K]V, K comparable, V any](m M, callbackFn func(K, V))
Executes a provided function once per each key/value pair in the Map.
func IsEmpty ¶
func IsEmpty[M ~map[K]V, K comparable, V any](m M) bool
IsEmpty returns true if the map is empty
func Keys ¶
func Keys[M ~map[K]V, K comparable, V any](m M) []K
Keys returns the keys of the map m. The keys will be in an indeterminate order.
func MapFunc ¶
func MapFunc[M ~map[K]V, K comparable, V any, W any](m M, callbackFn func(K, V) W) (mapped map[K]W)
MapFunc applies a transformation function to each value in the map and returns a new map with the transformed values.
func Reduce ¶
func Reduce[M ~map[K]V, K comparable, V any, I any](m M, callbackFn func(I, K, V) I, initialValue I) I
Reduce applies a reduction function to each value in the map and returns a single value.
func Size ¶
func Size[M ~map[K]V, K comparable, V any](m M) int
Size returns the number of key-value pairs in the map.
func Some ¶
func Some[M ~map[K]V, K comparable, V any](m M, callbackFn func(K, V) bool) bool
Some returns true if at least one key-value pair in the map causes the callback function to return true.
func Values ¶
func Values[M ~map[K]V, K comparable, V any](m M) []V
Values returns the values of the map m. The values will be in an indeterminate order.
Types ¶
type Map ¶
type Map[K comparable, V any] map[K]V
Map is a generic type that wraps a map with keys of type K and values of type V.
func From ¶
func From[M ~map[K]V, K comparable, V any](m M) Map[K, V]
From converts a map with keys of type K and values of type V into a Map type.
func New ¶
func New[K comparable, V any]() Map[K, V]
New allocates and initializes a map with keys of type K and values of type V.
func (*Map[K, V]) Clear ¶ added in v0.1.6
func (m *Map[K, V]) Clear()
Clear removes all entries from m, leaving it empty.
func (Map[K, V]) Clone ¶ added in v0.1.6
Clone returns a copy of m. This is a shallow clone: the new keys and values are set using ordinary assignment.
func (Map[K, V]) EqualFunc ¶ added in v0.1.6
EqualFunc is like Equal, but compares values using eq. Keys are still compared with ==.
func (Map[K, V]) Every ¶
Every returns true if all key-value pairs in the map cause the callback function to return true.
func (Map[K, V]) Filter ¶
Filter returns a new map containing only the key-value pairs for which the callback function returns true.
func (Map[K, V]) ForEach ¶
func (m Map[K, V]) ForEach(callbackFn func(K, V))
Executes a provided function once per each key/value pair in the Map.
func (Map[K, V]) Keys ¶
func (m Map[K, V]) Keys() []K
Keys returns the keys of the map m. The keys will be in an indeterminate order.