map_

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 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[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

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 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]) 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]) Start added in v0.0.10

func (i *Iter[K, V]) Start() (*Iter[K, V], K, V, bool)

Start is used with for loop construct like 'for i, val, ok := i.Start(); ok; val, ok = i.Next() { }'

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.

func (KeyIter[K, V]) Start added in v0.0.10

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

Start is used with for loop construct like 'for i, val, ok := i.Start(); ok; val, ok = i.Next() { }'

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.

func (ValIter[K, V]) Start added in v0.0.10

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

Start is used with for loop construct like 'for i, val, ok := i.Start(); ok; val, ok = i.Next() { }'

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