ordered

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: MIT Imports: 15 Imported by: 1

Documentation

Overview

Package ordered provides immutable ordered collection implementations

Package ordered provides ordered map iterator implementations

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

type Map[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Map is a collection implementation that provides elements access by an unique key.

func MapFromLoop

func MapFromLoop[K comparable, V any](next func() (K, V, bool)) Map[K, V]

MapFromLoop creates a map with elements retrieved converter the 'next' function

func NewMap

func NewMap[K comparable, V any](elements ...c.KV[K, V]) Map[K, V]

NewMap instantiates a map using key/value pairs

func NewMapOf

func NewMapOf[K comparable, V any](order []K, elements map[K]V) Map[K, V]

NewMapOf instantiates Map populated by the 'elements' map key/values

func WrapMap

func WrapMap[K comparable, V any](order []K, elements map[K]V) Map[K, V]

WrapMap instantiates ordered Map using a map and an order slice as internal storage.

func (Map[K, V]) All added in v0.0.12

func (m Map[K, V]) All(consumer func(K, V) bool)

All is used to iterate through the collection using `for ... range`. Supported since go 1.22 with GOEXPERIMENT=rangefunc enabled.

func (Map[K, V]) Contains

func (m Map[K, V]) Contains(key K) (ok bool)

Contains checks is the map contains a key

func (Map[K, V]) Conv

func (m Map[K, V]) Conv(converter func(K, V) (K, V, error)) breakLoop.Loop[K, V]

Conv returns a breakable loop that applies the 'converter' function to the collection elements

func (Map[K, V]) ConvKey

func (m Map[K, V]) ConvKey(converter func(K) (K, error)) breakLoop.Loop[K, V]

ConvKey returns a loop that applies the 'converter' function to keys of the map

func (Map[K, V]) ConvValue

func (m Map[K, V]) ConvValue(converter func(V) (V, error)) breakLoop.Loop[K, V]

ConvValue returns a breakable loop that applies the 'converter' function to values of the map

func (Map[K, V]) Convert

func (m Map[K, V]) Convert(converter func(K, V) (K, V)) kvloop.Loop[K, V]

Convert returns a loop that applies the 'converter' function to the collection elements

func (Map[K, V]) ConvertKey

func (m Map[K, V]) ConvertKey(by func(K) K) kvloop.Loop[K, V]

ConvertKey returns a loop that applies the 'converter' function to keys of the map

func (Map[K, V]) ConvertValue

func (m Map[K, V]) ConvertValue(converter func(V) V) kvloop.Loop[K, V]

ConvertValue returns a loop that applies the 'converter' function to values of the map

func (Map[K, V]) Filt

func (m Map[K, V]) Filt(predicate func(K, V) (bool, error)) breakLoop.Loop[K, V]

Filt returns a breakable loop consisting of elements that satisfy the condition of the 'predicate' function

func (Map[K, V]) FiltKey

func (m Map[K, V]) FiltKey(predicate func(K) (bool, error)) breakLoop.Loop[K, V]

FiltKey returns a loop consisting of key/value pairs where the key satisfies the condition of the 'predicate' function

func (Map[K, V]) FiltValue

func (m Map[K, V]) FiltValue(predicate func(V) (bool, error)) breakLoop.Loop[K, V]

FiltValue returns a breakable loop consisting of key/value pairs where the value satisfies the condition of the 'predicate' function

func (Map[K, V]) Filter

func (m Map[K, V]) Filter(predicate func(K, V) bool) kvloop.Loop[K, V]

Filter returns a loop consisting of elements that satisfy the condition of the 'predicate' function

func (Map[K, V]) FilterKey

func (m Map[K, V]) FilterKey(predicate func(K) bool) kvloop.Loop[K, V]

FilterKey returns a loop consisting of key/value pairs where the key satisfies the condition of the 'predicate' function

func (Map[K, V]) FilterValue

func (m Map[K, V]) FilterValue(predicate func(V) bool) kvloop.Loop[K, V]

FilterValue returns a loop consisting of key/value pairs where the value satisfies the condition of the 'predicate' function

func (Map[K, V]) First deprecated

func (m Map[K, V]) First() (MapIter[K, V], K, V, bool)

Deprecated: First is deprecated. Will be replaced by rance-over function iterator. First returns the first key/value pair of the map, an iterator to iterate over the remaining pair, and true\false marker of availability next pairs. If no more then ok==false.

func (Map[K, V]) Get

func (m Map[K, V]) Get(key K) (element V, ok bool)

Get returns the value for a key. If ok==false, then the map does not contain the key.

func (Map[K, V]) HasAny

func (m Map[K, V]) HasAny(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 (Map[K, V]) Head deprecated

func (m Map[K, V]) Head() MapIter[K, V]

Deprecated: Head is deprecated. Will be replaced by rance-over function iterator. Head creates an iterator to iterate through the collection.

func (Map[K, V]) IsEmpty

func (m Map[K, V]) IsEmpty() bool

IsEmpty returns true if the map is empty

func (Map[K, V]) Keys

func (m Map[K, V]) Keys() MapKeys[K]

Keys resutrns keys collection

func (Map[K, V]) Len

func (m Map[K, V]) Len() int

Len returns amount of elements

func (Map[K, V]) Loop

func (m Map[K, V]) Loop() kvloop.Loop[K, V]

Loop creates a loop to iterate through the collection.

func (Map[K, V]) Map

func (m Map[K, V]) Map() map[K]V

Map collects the key/value pairs into a new map

func (Map[K, V]) Reduce

func (m Map[K, V]) Reduce(merge func(K, K, V, V) (K, V)) (K, V)

Reduce reduces the key/value pairs of the map into an one pair using the 'merge' function

func (Map[K, V]) Sort

func (m Map[K, V]) Sort(comparer slice.Comparer[K]) Map[K, V]

Sort returns sorted by keys map

func (Map[K, V]) StableSort

func (m Map[K, V]) StableSort(comparer slice.Comparer[K]) Map[K, V]

StableSort returns sorted by keys map

func (Map[K, V]) String

func (m Map[K, V]) String() string

func (Map[K, V]) Tail deprecated

func (m Map[K, V]) Tail() MapIter[K, V]

Deprecated: Tail is deprecated. Will be replaced by rance-over function iterator. Tail creates an iterator pointing to the end of the map

func (Map[K, V]) Track

func (m Map[K, V]) Track(consumer func(K, V) error) error

Track applies the 'consumer' function for all key/value pairs until the consumer returns the c.Break to stop.

func (Map[K, V]) TrackEach

func (m Map[K, V]) TrackEach(consumer func(K, V))

TrackEach applies the 'consumer' function for every key/value pairs

func (Map[K, V]) Values

func (m Map[K, V]) Values() MapValues[K, V]

Values resutrns values collection

type MapIter

type MapIter[K comparable, V any] struct {
	// contains filtered or unexported fields
}

MapIter is the ordered key/value pairs Iterator implementation

func NewMapIter

func NewMapIter[K comparable, V any](uniques map[K]V, elements slice.Iter[K]) MapIter[K, V]

NewMapIter is the Iter constructor

func (*MapIter[K, V]) All added in v0.0.12

func (i *MapIter[K, V]) All(consumer func(key K, value V) bool)

All is used to iterate through the iterator using `for ... range`. Supported since go 1.22 with GOEXPERIMENT=rangefunc enabled.

func (*MapIter[K, V]) Next

func (i *MapIter[K, V]) Next() (key K, val V, ok bool)

Next returns the next key/value pair. The ok result indicates whether the pair was returned by the iterator. If ok == false, then the iteration must be completed.

func (*MapIter[K, V]) Size added in v0.0.12

func (i *MapIter[K, V]) Size() int

Size returns the iterator capacity

func (*MapIter[K, V]) Track

func (i *MapIter[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 Break

func (*MapIter[K, V]) TrackEach

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

TrackEach takes all key, value pairs retrieved by the iterator

type MapKeys

type MapKeys[K comparable] struct {
	// contains filtered or unexported fields
}

MapKeys is the wrapper for Map'm keys

func WrapKeys

func WrapKeys[K comparable](elements []K) MapKeys[K]

WrapKeys instantiates MapKeys using the elements as internal storage

func (MapKeys[K]) All added in v0.0.12

func (m MapKeys[K]) All(consumer func(K) bool)

All is used to iterate through the collection using `for ... range`. Supported since go 1.22 with GOEXPERIMENT=rangefunc enabled.

func (MapKeys[K]) Append

func (m MapKeys[K]) Append(out []K) []K

Append collects the values to the specified 'out' slice

func (MapKeys[K]) Conv

func (m MapKeys[K]) Conv(converter func(K) (K, error)) breakLoop.Loop[K]

Conv returns a breakable loop that applies the 'converter' function to the collection elements

func (MapKeys[K]) Convert

func (m MapKeys[K]) Convert(converter func(K) K) loop.Loop[K]

Convert returns a loop that applies the 'converter' function to the collection elements

func (MapKeys[K]) Filt

func (m MapKeys[K]) Filt(predicate func(K) (bool, error)) breakLoop.Loop[K]

Filt returns a breakable loop consisting of elements that satisfy the condition of the 'predicate' function

func (MapKeys[K]) Filter

func (m MapKeys[K]) Filter(filter func(K) bool) loop.Loop[K]

Filter returns a loop consisting of elements that satisfy the condition of the 'predicate' function

func (MapKeys[K]) First deprecated

func (m MapKeys[K]) First() (*slice.Iter[K], K, bool)

Deprecated: First is deprecated. Will be replaced by rance-over function iterator. First returns the first element of the collection, an iterator to iterate over the remaining elements, and true\false marker of availability next elements. If no more elements then ok==false.

func (MapKeys[K]) For

func (m MapKeys[K]) For(consumer func(K) error) error

For applies the 'consumer' function for every key until the consumer returns the c.Break to stop.

func (MapKeys[K]) ForEach

func (m MapKeys[K]) ForEach(consumer func(K))

ForEach applies the 'consumer' function for every element

func (MapKeys[K]) Get

func (m MapKeys[K]) Get(index int) (K, bool)

Get returns an element by the index, otherwise, if the provided index is ouf of the collection len, returns zero T and false in the second result

func (MapKeys[K]) HasAny

func (m MapKeys[K]) HasAny(predicate func(K) bool) bool

HasAny finds the first element that satisfies the 'predicate' function condition and returns true if successful

func (MapKeys[K]) Head deprecated

func (m MapKeys[K]) Head() slice.Iter[K]

Deprecated: Head is deprecated. Will be replaced by rance-over function iterator. Head creates an iterator to iterate through the collection.

func (MapKeys[K]) IsEmpty

func (m MapKeys[K]) IsEmpty() bool

IsEmpty returns true if the collection is empty

func (MapKeys[K]) Len

func (m MapKeys[K]) Len() int

Len returns amount of elements

func (MapKeys[K]) Loop added in v0.0.12

func (m MapKeys[K]) Loop() loop.Loop[K]

Loop creates a loop to iterate through the collection.

func (MapKeys[K]) Reduce

func (m MapKeys[K]) Reduce(merge func(K, K) K) K

Reduce reduces the elements into an one using the 'merge' function

func (MapKeys[K]) Slice

func (m MapKeys[K]) Slice() (out []K)

Slice collects the elements to a slice

func (MapKeys[K]) String

func (m MapKeys[K]) String() string

String returns string representation of the collection

type MapValues

type MapValues[K comparable, V any] struct {
	// contains filtered or unexported fields
}

MapValues is the wrapper for Map'm values.

func WrapVal

func WrapVal[K comparable, V any](order []K, elements map[K]V) MapValues[K, V]

WrapVal instantiates MapValues using elements as internal storage.

func (MapValues[K, V]) All added in v0.0.12

func (m MapValues[K, V]) All(consumer func(V) bool)

All is used to iterate through the collection using `for ... range`. Supported since go 1.22 with GOEXPERIMENT=rangefunc enabled.

func (MapValues[K, V]) Append

func (m MapValues[K, V]) Append(out []V) (values []V)

Append collects the values to the specified 'out' slice

func (MapValues[K, V]) Conv

func (m MapValues[K, V]) Conv(converter func(V) (V, error)) breakLoop.Loop[V]

Conv returns a breakable loop that applies the 'converter' function to the collection elements

func (MapValues[K, V]) Convert

func (m MapValues[K, V]) Convert(converter func(V) V) loop.Loop[V]

Convert returns a loop that applies the 'converter' function to the collection elements

func (MapValues[K, V]) Filt

func (m MapValues[K, V]) Filt(filter func(V) (bool, error)) breakLoop.Loop[V]

Filt returns a breakable loop consisting of elements that satisfy the condition of the 'predicate' function

func (MapValues[K, V]) Filter

func (m MapValues[K, V]) Filter(filter func(V) bool) loop.Loop[V]

Filter returns a loop consisting of elements that satisfy the condition of the 'predicate' function

func (MapValues[K, V]) First deprecated

func (m MapValues[K, V]) First() (*ValIter[K, V], V, bool)

Deprecated: First is deprecated. Will be replaced by rance-over function iterator. First returns the first element of the collection, an iterator to iterate over the remaining elements, and true\false marker of availability next elements. If no more elements then ok==false.

func (MapValues[K, V]) For

func (m MapValues[K, V]) For(consumer func(V) error) error

For applies the 'consumer' function for every value until the consumer returns the c.Break to stop.

func (MapValues[K, V]) ForEach

func (m MapValues[K, V]) ForEach(consumer func(V))

ForEach applies the 'consumer' function for every value

func (MapValues[K, V]) Get

func (m MapValues[K, V]) Get(index int) (V, bool)

Get returns an element by the index, otherwise, if the provided index is ouf of the collection len, returns zero T and false in the second result

func (MapValues[K, V]) HasAny

func (m MapValues[K, V]) HasAny(predicate func(V) bool) bool

HasAny finds the first element that satisfies the 'predicate' function condition and returns true if successful

func (MapValues[K, V]) Head deprecated

func (m MapValues[K, V]) Head() *ValIter[K, V]

Deprecated: Head is deprecated. Will be replaced by rance-over function iterator. Head creates an iterator to iterate through the collection.

func (MapValues[K, V]) IsEmpty

func (m MapValues[K, V]) IsEmpty() bool

IsEmpty returns true if the collection is empty

func (MapValues[K, V]) Len

func (m MapValues[K, V]) Len() int

Len returns amount of elements

func (MapValues[K, V]) Loop

func (m MapValues[K, V]) Loop() loop.Loop[V]

Loop creates a loop to iterate through the collection.

func (MapValues[K, V]) Reduce

func (m MapValues[K, V]) Reduce(merge func(V, V) V) V

Reduce reduces the elements into an one using the 'merge' function

func (MapValues[K, V]) Slice

func (m MapValues[K, V]) Slice() (values []V)

Slice collects the values to a slice

func (MapValues[K, V]) String

func (m MapValues[K, V]) String() string

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

Set is a collection implementation that provides storage for unique elements, prevents duplication, and guarantees access order. The elements must be comparable.

func NewSet

func NewSet[T comparable](elements ...T) Set[T]

NewSet instantiates set and copies elements to it

func SetFromLoop

func SetFromLoop[T comparable](next func() (T, bool)) Set[T]

SetFromLoop creates a set with elements retrieved by the 'next' function. The next returns an element with true or zero value with false if there are no more elements.

func WrapSet

func WrapSet[T comparable](order []T, elements map[T]struct{}) Set[T]

WrapSet creates a set using a map and an order slice as the internal storage.

func (Set[T]) All added in v0.0.12

func (s Set[T]) All(consumer func(T) bool)

All is used to iterate through the collection using `for ... range`. Supported since go 1.22 with GOEXPERIMENT=rangefunc enabled.

func (Set[T]) Append

func (s Set[T]) Append(out []T) []T

Append collects the values to the specified 'out' slice

func (Set[T]) Contains

func (s Set[T]) Contains(element T) (ok bool)

Contains checks is the collection contains an element

func (Set[T]) Conv

func (s Set[T]) Conv(converter func(T) (T, error)) breakLoop.Loop[T]

Conv returns a breakable loop that applies the 'converter' function to the collection elements

func (Set[T]) Convert

func (s Set[T]) Convert(converter func(T) T) loop.Loop[T]

Convert returns a loop that applies the 'converter' function to the collection elements

func (Set[T]) Filt

func (s Set[T]) Filt(predicate func(T) (bool, error)) breakLoop.Loop[T]

Filt returns a breakable loop consisting of elements that satisfy the condition of the 'predicate' function

func (Set[T]) Filter

func (s Set[T]) Filter(predicate func(T) bool) loop.Loop[T]

Filter returns a loop consisting of elements that satisfy the condition of the 'predicate' function

func (Set[T]) First deprecated

func (s Set[T]) First() (*slice.Iter[T], T, bool)

Deprecated: First is deprecated. Will be replaced by rance-over function iterator. First returns the first element of the collection, an iterator to iterate over the remaining elements, and true\false marker of availability next elements. If no more elements then ok==false.

func (Set[T]) For

func (s Set[T]) For(consumer func(T) error) error

For applies the 'consumer' function for every element until the consumer returns the c.Break to stop.

func (Set[T]) ForEach

func (s Set[T]) ForEach(consumer func(T))

ForEach applies the 'consumer' function for every element

func (Set[T]) HasAny

func (s Set[T]) HasAny(predicate func(T) bool) bool

HasAny finds the first element that satisfies the 'predicate' function condition and returns true if successful

func (Set[T]) Head deprecated

func (s Set[T]) Head() slice.Iter[T]

Deprecated: Head is deprecated. Will be replaced by rance-over function iterator. Head creates an iterator to iterate through the collection.

func (Set[T]) IsEmpty

func (s Set[T]) IsEmpty() bool

IsEmpty returns true if the collection is empty

func (Set[T]) Last

func (s Set[T]) Last() (*slice.Iter[T], T, bool)

Last returns the latest element of the collection, an iterator to reverse iterate over the remaining elements, and true\false marker of availability previous elements. If no more elements then ok==false.

func (Set[T]) Len

func (s Set[T]) Len() int

Len returns amount of elements

func (Set[T]) Loop

func (s Set[T]) Loop() loop.Loop[T]

Loop creates a loop to iterate through the collection.

func (Set[T]) Reduce

func (s Set[T]) Reduce(merge func(T, T) T) T

Reduce reduces the elements into an one using the 'merge' function

func (Set[T]) Slice

func (s Set[T]) Slice() []T

Slice collects the elements to a slice

func (Set[T]) Sort

func (s Set[T]) Sort(comparer slice.Comparer[T]) Set[T]

Sort sorts the elements

func (Set[T]) StableSort

func (s Set[T]) StableSort(comparer slice.Comparer[T]) Set[T]

StableSort sorts the elements

func (Set[T]) String

func (s Set[T]) String() string

func (Set[T]) Tail deprecated

func (s Set[T]) Tail() slice.Iter[T]

Deprecated: Tail is deprecated. Will be replaced by rance-over function iterator. Tail creates an iterator pointing to the end of the collection

type ValIter

type ValIter[K comparable, V any] struct {
	// contains filtered or unexported fields
}

ValIter is the Iteratoc over Map values

func NewValIter

func NewValIter[K comparable, V any](elements []K, uniques map[K]V) *ValIter[K, V]

NewValIter is default ValIter constructor

func (*ValIter[K, V]) All added in v0.0.12

func (i *ValIter[K, V]) All(consumer func(element V) bool)

All is used to iterate through the iterator using `for ... range`. Supported since go 1.22 with GOEXPERIMENT=rangefunc enabled.

func (*ValIter[K, V]) For

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

For takes elements retrieved by the iterator. Can be interrupt by returning Break

func (*ValIter[K, V]) ForEach

func (i *ValIter[K, V]) ForEach(consumer func(element V))

ForEach FlatIter all elements retrieved by the iterator

func (*ValIter[K, V]) Next

func (i *ValIter[K, V]) Next() (val 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 (*ValIter[K, V]) Size added in v0.0.12

func (i *ValIter[K, V]) Size() int

Size returns the iterator capacity

Directories

Path Synopsis
Package map_ provides immutale ordered.Map constructors
Package map_ provides immutale ordered.Map constructors
Package set provides ordered.Set constructors and helpers
Package set provides ordered.Set constructors and helpers

Jump to

Keyboard shortcuts

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