Documentation ¶
Overview ¶
Package map_ provides map processing helper functions
Index ¶
- Variables
- func AppendKeys[M ~map[K]V, K comparable, V any](elements M, out []K) []K
- func AppendValues[M ~map[K]V, K comparable, V any](elements M, out []V) []V
- func Clone[M ~map[K]V, K comparable, V any](elements M) M
- func Contains[M ~map[K]V, K comparable, V any](m M, key K) (ok bool)
- func Conv[M ~map[K]V, K, Kto comparable, V, Vto any](elements M, keyConverter func(K) (Kto, error), ...) (map[Kto]Vto, error)
- func Convert[M ~map[K]V, K, Kto comparable, V, Vto any](elements M, keyConverter func(K) Kto, valConverter func(V) Vto) map[Kto]Vto
- func ConvertKeys[M ~map[K]V, K, Kto comparable, V any](elements M, by func(K) Kto) map[Kto]V
- func ConvertValues[M ~map[K]V, V, Vto any, K comparable](elements M, by func(V) Vto) map[K]Vto
- func DeepClone[M ~map[K]V, K comparable, V any](elements M, copier func(V) V) M
- func Empty[M ~map[K]V, K comparable, V any](val M) bool
- func Filter[M ~map[K]V, K comparable, V any](elements M, filter func(K, V) bool) map[K]V
- func FilterKeys[M ~map[K]V, K comparable, V any](elements M, filter func(K) bool) map[K]V
- func FilterValues[M ~map[K]V, K comparable, V any](elements M, filter func(V) bool) map[K]V
- func For[M ~map[K]V, K comparable, V any](elements M, walker func(c.KV[K, V]) error) error
- func ForEach[M ~map[K]V, K comparable, V any](elements M, walker func(c.KV[K, V]))
- func ForEachKey[M ~map[K]V, K comparable, V any](elements M, walker func(K))
- func ForEachOrdered[M ~map[K]V, K comparable, V any](order []K, elements M, walker func(c.KV[K, V]))
- func ForEachOrderedValues[M ~map[K]V, K comparable, V any](order []K, elements M, walker func(V))
- func ForEachValue[M ~map[K]V, K comparable, V any](elements M, walker func(V))
- func ForKeys[M ~map[K]V, K comparable, V any](elements M, walker func(K) error) error
- func ForOrdered[M ~map[K]V, K comparable, V any](order []K, elements M, walker func(c.KV[K, V]) error) error
- func ForOrderedValues[M ~map[K]V, K comparable, V any](order []K, elements M, walker func(V) error) error
- func ForValues[M ~map[K]V, K comparable, V any](elements M, walker func(V) error) error
- func Generate[K comparable, V any](next func() (K, V, bool, error)) (map[K]V, error)
- func GenerateResolv[K comparable, V any](next func() (K, V, bool, error), resolv func(bool, K, V, V) V) (map[K]V, error)
- func Get[M ~map[K]V, K comparable, V any](m M, key K) V
- func GetOk[M ~map[K]V, K comparable, V any](m M, key K) (val V, ok bool)
- func Getter[M ~map[K]V, K comparable, V any](m M) func(key K) V
- func GetterOk[M ~map[K]V, K comparable, V any](m M) func(key K) (V, bool)
- func GroupOfLoop[S any, K comparable, V any](source S, hasNext func(S) bool, getNext func(S) (K, V, error)) (map[K][]V, error)
- func HasAny[M ~map[K]V, K comparable, V any](elements M, predicate func(K, V) bool) bool
- func KeyChecker[M ~map[K]V, K comparable, V any](m M) func(key K) (ok bool)
- func Keys[M ~map[K]V, K comparable, V any](elements M) []K
- func NotEmpty[M ~map[K]V, K comparable, V any](val M) bool
- func Of[K comparable, V any](elements ...c.KV[K, V]) map[K]V
- func OfLoop[S any, K comparable, V any](source S, hasNext func(S) bool, getNext func(S) (K, V, error)) (map[K]V, error)
- func OfLoopResolv[S any, K comparable, E, V any](source S, hasNext func(S) bool, getNext func(S) (K, E, error), ...) (map[K]V, error)
- func Reduce[M ~map[K]V, K comparable, V any](elements M, merge func(K, K, V, V) (K, V)) (rk K, rv V)
- func ToSlice[M ~map[K]V, K comparable, V any, T any](elements M, converter func(key K, val V) T) []T
- func ToSlicee[M ~map[K]V, K comparable, V any, T any](elements M, converter func(key K, val V) (T, error)) ([]T, error)
- func ToString[M ~map[K]V, K comparable, V any](elements M) string
- func ToStringOrdered[M ~map[K]V, K comparable, V any](order []K, elements M) string
- func ToStringOrderedf[M ~map[K]V, K comparable, V any](order []K, elements M, kvFormat, delim string) string
- func ToStringf[M ~map[K]V, K comparable, V any](elements M, kvFormat, delim string) string
- func Track[M ~map[K]V, K comparable, V any](elements M, tracker func(K, V) error) error
- func TrackEach[M ~map[K]V, K comparable, V any](elements M, tracker func(K, V))
- func TrackEachOrdered[M ~map[K]V, K comparable, V any](order []K, uniques M, tracker func(K, V))
- func TrackOrdered[M ~map[K]V, K comparable, V any](order []K, elements M, tracker func(K, V) error) error
- func Values[M ~map[K]V, K comparable, V any](elements M) []V
- func ValuesConverted[M ~map[K]V, K comparable, V, Vto any](elements M, by func(V) Vto) []Vto
- type Iter
- type KeyIter
- type ValIter
Constants ¶
This section is empty.
Variables ¶
var ErrBreak = c.ErrBreak
ErrBreak is For, Track breaker
Functions ¶
func AppendKeys ¶ added in v0.0.7
func AppendKeys[M ~map[K]V, K comparable, V any](elements M, out []K) []K
AppendKeys collects keys of the specified 'elements' map into the specified 'out' slice
func AppendValues ¶ added in v0.0.7
func AppendValues[M ~map[K]V, K comparable, V any](elements M, out []V) []V
AppendValues collects values of the specified 'elements' map into the specified 'out' slice
func Clone ¶ added in v0.0.5
func Clone[M ~map[K]V, K comparable, V any](elements M) M
Clone makes a copy of the 'elements' map. The values are copied as is.
func Contains ¶ added in v0.0.10
func Contains[M ~map[K]V, K comparable, V any](m M, key K) (ok bool)
Contains checks is the map contains a key
func Conv ¶ added in v0.0.8
func Conv[M ~map[K]V, K, Kto comparable, V, Vto any](elements M, keyConverter func(K) (Kto, error), valConverter func(V) (Vto, error)) (map[Kto]Vto, error)
Conv creates a map with converted keys and values
func Convert ¶ added in v0.0.8
func Convert[M ~map[K]V, K, Kto comparable, V, Vto any](elements M, keyConverter func(K) Kto, valConverter func(V) Vto) map[Kto]Vto
Convert creates a map with converted keys and values
func ConvertKeys ¶ added in v0.0.8
func ConvertKeys[M ~map[K]V, K, Kto comparable, V any](elements M, by func(K) Kto) map[Kto]V
ConvertKeys creates a map with converted keys
func ConvertValues ¶ added in v0.0.5
func ConvertValues[M ~map[K]V, V, Vto any, K comparable](elements M, by func(V) Vto) map[K]Vto
ConvertValues creates a map with converted values
func DeepClone ¶ added in v0.0.5
func DeepClone[M ~map[K]V, K comparable, V any](elements M, copier func(V) V) M
DeepClone makes a copy of the 'elements' map. The values are copied by the 'copier' function
func Empty ¶ added in v0.0.8
func Empty[M ~map[K]V, K comparable, V any](val M) bool
Empty checks the val map is empty
func Filter ¶ added in v0.0.10
func Filter[M ~map[K]V, K comparable, V any](elements M, filter func(K, V) bool) map[K]V
Filter creates a map containing only the filtered elements
func FilterKeys ¶ added in v0.0.10
func FilterKeys[M ~map[K]V, K comparable, V any](elements M, filter func(K) bool) map[K]V
FilterKeys creates a map containing only the filtered elements
func FilterValues ¶ added in v0.0.10
func FilterValues[M ~map[K]V, K comparable, V any](elements M, filter func(V) bool) map[K]V
FilterValues creates a map containing only the filtered elements
func For ¶
For applies the 'walker' function for key/value pairs from the elements. Return the c.ErrBreak to stop.
func ForEach ¶
func ForEach[M ~map[K]V, K comparable, V any](elements M, walker func(c.KV[K, V]))
ForEach applies the 'walker' function for every key/value pair from the elements map
func ForEachKey ¶
func ForEachKey[M ~map[K]V, K comparable, V any](elements M, walker func(K))
ForEachKey applies the 'walker' function for every key from from the 'elements' map
func ForEachOrdered ¶
func ForEachOrdered[M ~map[K]V, K comparable, V any](order []K, elements M, walker func(c.KV[K, V]))
ForEachOrdered applies the 'walker' function for every key/value pair from the 'elements' map in order of the 'order' slice.
func ForEachOrderedValues ¶
func ForEachOrderedValues[M ~map[K]V, K comparable, V any](order []K, elements M, walker func(V))
ForEachOrderedValues applies the 'walker' function for each value from the 'elements' map in order of the 'order' slice
func ForEachValue ¶
func ForEachValue[M ~map[K]V, K comparable, V any](elements M, walker func(V))
ForEachValue applies the 'walker' function for every value from from the 'elements' map
func ForKeys ¶
func ForKeys[M ~map[K]V, K comparable, V any](elements M, walker func(K) error) error
ForKeys applies the 'walker' function for keys from the 'elements' map . Return the c.ErrBreak to stop.
func ForOrdered ¶
func ForOrdered[M ~map[K]V, K comparable, V any](order []K, elements M, walker func(c.KV[K, V]) error) error
ForOrdered applies the 'walker' function for every key/value pair from the 'elements' map in order of the 'order' slice. Return the c.ErrBreak to stop.
func ForOrderedValues ¶
func ForOrderedValues[M ~map[K]V, K comparable, V any](order []K, elements M, walker func(V) error) error
ForOrderedValues applies the 'walker' function for values from the 'elements' map in order of the 'order' slice. Return the c.ErrBreak to stop..
func ForValues ¶
func ForValues[M ~map[K]V, K comparable, V any](elements M, walker func(V) error) error
ForValues applies the 'walker' function for values from the 'elements' map . Return the c.ErrBreak to stop..
func Generate ¶ added in v0.0.5
func Generate[K comparable, V any](next func() (K, V, bool, error)) (map[K]V, error)
Generate builds a map by an generator function. The next returns a key\value pair, or false if the generation is over, or an error.
func GenerateResolv ¶ added in v0.0.5
func GenerateResolv[K comparable, V any](next func() (K, V, bool, error), resolv func(bool, K, V, V) V) (map[K]V, error)
GenerateResolv builds a map by an generator function. The next returns a key\value pair, or false if the generation is over, or an error. The resolv selects value for duplicated keys.
func Get ¶ added in v0.0.10
func Get[M ~map[K]V, K comparable, V any](m M, key K) V
Get returns the value by the specified key from the map m or zero if the map doesn't contain that key
func GetOk ¶ added in v0.0.10
func GetOk[M ~map[K]V, K comparable, V any](m M, key K) (val V, ok bool)
GetOk returns the value, and true by the specified key from the map m or zero and false if the map doesn't contain that key
func Getter ¶ added in v0.0.10
func Getter[M ~map[K]V, K comparable, V any](m M) func(key K) V
Getter creates a function that can be used for retrieving a value from the map m by a key
func GetterOk ¶ added in v0.0.10
func GetterOk[M ~map[K]V, K comparable, V any](m M) func(key K) (V, bool)
GetterOk creates a function that can be used for retrieving a value from the map m by a key
func GroupOfLoop ¶ added in v0.0.5
func GroupOfLoop[S any, K comparable, V any](source S, hasNext func(S) bool, getNext func(S) (K, V, error)) (map[K][]V, error)
GroupOfLoop builds a map of slices by iterating over elements, extracting key\value pairs and grouping the values for each key in the slices. The hasNext specifies a predicate that tests existing of a next pair in the source. The getNext extracts the pair.
func HasAny ¶ added in v0.0.7
func HasAny[M ~map[K]V, K comparable, V any](elements M, predicate func(K, V) bool) bool
HasAny finds the first key/value pair that satisfies the 'predicate' function condition and returns true if successful
func KeyChecker ¶ added in v0.0.10
func KeyChecker[M ~map[K]V, K comparable, V any](m M) func(key K) (ok bool)
KeyChecker creates a function that can be used to check if the map contains a key
func Keys ¶
func Keys[M ~map[K]V, K comparable, V any](elements M) []K
Keys returns keys of the 'elements' map as a slice
func NotEmpty ¶ added in v0.0.8
func NotEmpty[M ~map[K]V, K comparable, V any](val M) bool
NotEmpty checks the val map is not empty
func Of ¶ added in v0.0.7
func Of[K comparable, V any](elements ...c.KV[K, V]) map[K]V
Of instantiates a ap from the specified key/value pairs
func OfLoop ¶ added in v0.0.5
func OfLoop[S any, K comparable, V any](source S, hasNext func(S) bool, getNext func(S) (K, V, error)) (map[K]V, error)
OfLoop builds a map by iterating key\value pairs of a source. The hasNext specifies a predicate that tests existing of a next pair in the source. The getNext extracts the pair.
func OfLoopResolv ¶ added in v0.0.5
func OfLoopResolv[S any, K comparable, E, V any](source S, hasNext func(S) bool, getNext func(S) (K, E, error), resolv func(bool, K, V, E) V) (map[K]V, error)
OfLoopResolv builds a map by iterating elements of a source. The hasNext specifies a predicate that tests existing of a next pair in the source. The getNext extracts the element. The resolv values for duplicated keys.
func Reduce ¶ added in v0.0.7
func Reduce[M ~map[K]V, K comparable, V any](elements M, merge func(K, K, V, V) (K, V)) (rk K, rv V)
Reduce reduces the key/value pairs by the 'next' function into an one pair using the 'merge' function
func ToSlice ¶ added in v0.0.8
func ToSlice[M ~map[K]V, K comparable, V any, T any](elements M, converter func(key K, val V) T) []T
ToSlice collects key\value elements to a slice by applying the specified converter to evety element
func ToSlicee ¶ added in v0.0.8
func ToSlicee[M ~map[K]V, K comparable, V any, T any](elements M, converter func(key K, val V) (T, error)) ([]T, error)
ToSlicee collects key\value elements to a slice by applying the specified erroreable converter to evety element
func ToString ¶
func ToString[M ~map[K]V, K comparable, V any](elements M) string
ToString converts elements to the string representation
func ToStringOrdered ¶
func ToStringOrdered[M ~map[K]V, K comparable, V any](order []K, elements M) string
ToStringOrdered converts elements to the string representation according to the order
func ToStringOrderedf ¶
func ToStringOrderedf[M ~map[K]V, K comparable, V any](order []K, elements M, kvFormat, delim string) string
ToStringOrderedf converts elements to a string representation using a key/value pair format and a delimeter. In order
func ToStringf ¶
func ToStringf[M ~map[K]V, K comparable, V any](elements M, kvFormat, delim string) string
ToStringf converts elements to a string representation using a key/value pair format and a delimeter
func Track ¶
func Track[M ~map[K]V, K comparable, V any](elements M, tracker func(K, V) error) error
Track applies the 'tracker' function for every key/value pairs from the 'elements' map. Return the c.ErrBreak to stop
func TrackEach ¶
func TrackEach[M ~map[K]V, K comparable, V any](elements M, tracker func(K, V))
TrackEach applies the 'tracker' function for every key/value pairs from the 'elements' map
func TrackEachOrdered ¶
func TrackEachOrdered[M ~map[K]V, K comparable, V any](order []K, uniques M, tracker func(K, V))
TrackEachOrdered applies the 'tracker' function for evey key/value pair from the 'elements' map in order of the 'order' slice
func TrackOrdered ¶
func TrackOrdered[M ~map[K]V, K comparable, V any](order []K, elements M, tracker func(K, V) error) error
TrackOrdered applies the 'tracker' function for key/value pairs from the 'elements' map in order of the 'order' slice. Return the c.ErrBreak to stop
func Values ¶ added in v0.0.5
func Values[M ~map[K]V, K comparable, V any](elements M) []V
Values returns values of the 'elements' map as a slice
func ValuesConverted ¶ added in v0.0.5
func ValuesConverted[M ~map[K]V, K comparable, V, Vto any](elements M, by func(V) Vto) []Vto
ValuesConverted makes a slice of converted map values
Types ¶
type Iter ¶ added in v0.0.7
type Iter[K comparable, V any] struct { // contains filtered or unexported fields }
Iter is the embedded map based Iterator implementation
func NewIter ¶ added in v0.0.7
func NewIter[K comparable, V any](elements map[K]V) Iter[K, V]
NewIter returns the Iter based on map elements
func (*Iter[K, V]) Next ¶ added in v0.0.7
Next returns the next element. The ok result indicates whether the element was returned by the iterator. If ok == false, then the iteration must be completed.
func (*Iter[K, V]) Start ¶ added in v0.0.10
Start is used with for loop construct like 'for i, val, ok := i.Start(); ok; val, ok = i.Next() { }'
type KeyIter ¶ added in v0.0.7
type KeyIter[K comparable, V any] struct { Iter[K, V] }
KeyIter is the Iterator implementation that provides iterating over keys of a key/value pairs iterator
func NewKeyIter ¶ added in v0.0.7
func NewKeyIter[K comparable, V any](uniques map[K]V) KeyIter[K, V]
NewKeyIter instantiates a map keys iterator
func (KeyIter[K, V]) For ¶ added in v0.0.7
For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak
func (KeyIter[K, V]) ForEach ¶ added in v0.0.7
func (i KeyIter[K, V]) ForEach(walker func(element K))
ForEach FlatIter all elements retrieved by the iterator
type ValIter ¶ added in v0.0.7
type ValIter[K comparable, V any] struct { Iter[K, V] }
ValIter is a map values iterator
func NewValIter ¶ added in v0.0.7
func NewValIter[K comparable, V any](uniques map[K]V) ValIter[K, V]
NewValIter is the main values iterator constructor
func (ValIter[K, V]) For ¶ added in v0.0.7
For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak
func (ValIter[K, V]) ForEach ¶ added in v0.0.7
func (i ValIter[K, V]) ForEach(walker func(element V))
ForEach FlatIter all elements retrieved by the iterator
Directories ¶
Path | Synopsis |
---|---|
Package clone provides map clone aliases
|
Package clone provides map clone aliases |
Package convert provides key, value convert adapters
|
Package convert provides key, value convert adapters |
Package filter provides helpers for filtering keys or values of a map
|
Package filter provides helpers for filtering keys or values of a map |
Package group provides short aliases for functions that are used to group key/values retieved from a source
|
Package group provides short aliases for functions that are used to group key/values retieved from a source |
Package resolv provides values resolvers for maps thath builded by iterating over key/values loop, slice or collection
|
Package resolv provides values resolvers for maps thath builded by iterating over key/values loop, slice or collection |