map_

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2023 License: MIT Imports: 9 Imported by: 3

Documentation

Overview

Package map_ provides map processing helper functions

Index

Constants

This section is empty.

Variables

View Source
var ErrBreak = c.ErrBreak

ErrBreak is For, Track breaker

Functions

func AppendKeys added in v0.0.7

func AppendKeys[K comparable, V any, M ~map[K]V](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[V any, K comparable, M ~map[K]V](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 ConvertValues added in v0.0.5

func ConvertValues[V, Vto any, K comparable, M ~map[K]V](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 For

func For[M ~map[K]V, K comparable, V any](elements M, walker func(c.KV[K, V]) error) error

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 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 Keys

func Keys[K comparable, V any, M ~map[K]V](elements M) []K

Keys returns keys of the 'elements' map as a slice

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, V, K, 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 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[V any, K comparable, M ~map[K]V](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]) Cap added in v0.0.7

func (i *Iter[K, V]) Cap() int

Cap returns the size of the map

func (*Iter[K, V]) Next added in v0.0.7

func (i *Iter[K, V]) Next() (key K, value V, ok bool)

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]) Track added in v0.0.7

func (i *Iter[K, V]) Track(traker func(key K, value V) error) error

Track takes key, value pairs retrieved by the iterator. Can be interrupt by returning ErrBreak

func (*Iter[K, V]) TrackEach added in v0.0.7

func (i *Iter[K, V]) TrackEach(traker func(key K, value V))

TrackEach takes all key, value pairs retrieved by the iterator

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]) Cap added in v0.0.7

func (i KeyIter[K, V]) Cap() int

Cap returns the iterator capacity

func (KeyIter[K, V]) For added in v0.0.7

func (i KeyIter[K, V]) For(walker func(element K) error) error

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

func (KeyIter[K, V]) Next added in v0.0.7

func (i KeyIter[K, V]) Next() (K, bool)

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.

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]) Cap added in v0.0.7

func (i ValIter[K, V]) Cap() int

Cap returns the size of the map

func (ValIter[K, V]) For added in v0.0.7

func (i ValIter[K, V]) For(walker func(element V) error) error

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

func (ValIter[K, V]) Next added in v0.0.7

func (i ValIter[K, V]) Next() (V, bool)

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.

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL