mutable

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2025 License: MIT Imports: 14 Imported by: 2

Documentation

Overview

Package mutable provides implementations of mutable containers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMapOrdered added in v0.0.16

func NewMapOrdered[K comparable, V any](elements ...c.KV[K, V]) *ordered.Map[K, V]

NewMapOrdered instantiates an ordered map using key/value pairs

func NewSetOrdered added in v0.0.16

func NewSetOrdered[T comparable](elements ...T) *ordered.Set[T]

NewSetOrdered instantiates ordered set and copies elements to it

Types

type Map

type Map[K comparable, V any] map[K]V

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

func MapFromSeq2 added in v0.0.15

func MapFromSeq2[K comparable, V any](seq seq.Seq2[K, V]) *Map[K, V]

MapFromSeq2 creates a map with elements retrieved by the seq.

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 NewMapCap

func NewMapCap[K comparable, V any](capacity int) *Map[K, V]

NewMapCap instantiates Map with a predefined capacity

func NewMapOf

func NewMapOf[K comparable, V any](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](elements map[K]V) *Map[K, V]

WrapMap instantiates Map using a map 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 key, val := range`.

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)) seq.SeqE[c.KV[K, V]]

Conv returns an errorable seq 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)) seq.SeqE[c.KV[K, V]]

ConvKey returns an errorable seq 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)) seq.SeqE[c.KV[K, V]]

ConvValue returns an errorable seq 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)) seq.Seq2[K, V]

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

func (Map[K, V]) ConvertKey

func (m Map[K, V]) ConvertKey(converter func(K) K) seq.Seq2[K, V]

ConvertKey returns a seq 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) seq.Seq2[K, V]

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

func (*Map[K, V]) Delete

func (m *Map[K, V]) Delete(keys ...K)

Delete removes value by their keys from the map

func (*Map[K, V]) DeleteOne

func (m *Map[K, V]) DeleteOne(key K)

DeleteOne removes a value by the key from the map

func (Map[K, V]) Filt

func (m Map[K, V]) Filt(filter func(K, V) (bool, error)) seq.SeqE[c.KV[K, V]]

Filt returns an errorable seq consisting of elements that satisfy the condition of the 'filter' function

func (Map[K, V]) FiltKey

func (m Map[K, V]) FiltKey(filter func(K) (bool, error)) seq.SeqE[c.KV[K, V]]

FiltKey returns an errorable seq consisting of key/value pairs where the key satisfies the condition of the 'filter' function

func (Map[K, V]) FiltValue

func (m Map[K, V]) FiltValue(filter func(V) (bool, error)) seq.SeqE[c.KV[K, V]]

FiltValue returns an errorable seq consisting of key/value pairs where the value satisfies the condition of the 'filter' function

func (Map[K, V]) Filter

func (m Map[K, V]) Filter(filter func(K, V) bool) seq.Seq2[K, V]

Filter returns a seq consisting of elements that satisfy the condition of the 'filter' function

func (Map[K, V]) FilterKey

func (m Map[K, V]) FilterKey(filter func(K) bool) seq.Seq2[K, V]

FilterKey returns a seq consisting of key/value pairs where the key satisfies the condition of the 'filter' function

func (Map[K, V]) FilterValue

func (m Map[K, V]) FilterValue(filter func(V) bool) seq.Seq2[K, V]

FilterValue returns a seq consisting of key/value pairs where the value satisfies the condition of the 'filter' function

func (*Map[K, V]) Get

func (m *Map[K, V]) Get(key K) (val 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(condition func(K, V) bool) bool

HasAny checks whether the map contains a key\value pair that satisfies the condition.

func (*Map[K, V]) Head

func (m *Map[K, V]) Head() (K, V, bool)

Head returns the first key\value pair.

func (*Map[K, V]) Immutable

func (m *Map[K, V]) Immutable() immutable.Map[K, V]

Immutable converts to an immutable map instance

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() immutable.MapKeys[K, V]

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]) Map

func (m *Map[K, V]) Map() (out 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 K, v V)

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

func (*Map[K, V]) Remove

func (m *Map[K, V]) Remove(key K) (v V, ok bool)

Remove removes value by key and return it

func (*Map[K, V]) Set

func (m *Map[K, V]) Set(key K, value V)

Set sets the value for a key

func (*Map[K, V]) SetMap

func (m *Map[K, V]) SetMap(other c.TrackEach[K, V])

SetMap inserts all elements from the 'other' map

func (*Map[K, V]) SetNew

func (m *Map[K, V]) SetNew(key K, value V) bool

SetNew sets the value fo a key only if the key is not exists in the map

func (*Map[K, V]) Sort added in v0.0.11

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

Sort sorts keys in-place (no copy)

func (*Map[K, V]) StableSort added in v0.0.11

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

StableSort sorts keys in-place (no copy)

func (*Map[K, V]) String

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

String string representation on the map

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() immutable.MapValues[K, V]

Values resutrns values collection

type Set

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

Set is a collection implementation that provides element uniqueness. The elements must be comparable.

func NewSet

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

NewSet instantiates set and copies elements to it

func NewSetCap

func NewSetCap[T comparable](capacity int) *Set[T]

NewSetCap creates a set with a predefined capacity

func SetFromSeq added in v0.0.15

func SetFromSeq[T comparable](seq seq.Seq[T]) *Set[T]

SetFromSeq creates a set with elements retrieved by the seq.

func WrapSet

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

WrapSet creates a set using a map as the internal storage.

func (*Set[T]) Add

func (s *Set[T]) Add(elements ...T)

Add adds elements in the collection

func (*Set[T]) AddAll

func (s *Set[T]) AddAll(elements seq.Seq[T])

AddAll inserts all elements from the "other" sequence.

func (*Set[T]) AddAllNew

func (s *Set[T]) AddAllNew(other seq.Seq[T]) (ok bool)

AddAllNew inserts elements from the "other" sequence if they are not contained in the collection.

func (*Set[T]) AddNew

func (s *Set[T]) AddNew(elements ...T) bool

AddNew inserts elements if they are not contained in the collection

func (*Set[T]) AddOne

func (s *Set[T]) AddOne(element T)

AddOne adds an element in the collection

func (*Set[T]) AddOneNew

func (s *Set[T]) AddOneNew(element T) (ok bool)

AddOneNew inserts an element if it is not contained in the collection

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 e := range`.

func (*Set[T]) Append

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

Append collects the values to the specified 'out' slice

func (*Set[T]) Clone

func (s *Set[T]) Clone() *Set[T]

Clone returns copy of the collection

func (*Set[T]) Contains

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

Contains checks if the collection contains an element

func (*Set[T]) Conv

func (s *Set[T]) Conv(converter func(T) (T, error)) seq.SeqE[T]

Conv returns an errorable seq that applies the 'converter' function to the collection elements

func (*Set[T]) Convert

func (s *Set[T]) Convert(converter func(T) T) seq.Seq[T]

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

func (*Set[T]) Delete

func (s *Set[T]) Delete(elements ...T)

Delete removes elements from the collection

func (*Set[T]) DeleteActual

func (s *Set[T]) DeleteActual(elements ...T) bool

DeleteActual removes elements only if they are contained in the collection

func (*Set[T]) DeleteActualOne

func (s *Set[T]) DeleteActualOne(element T) (ok bool)

DeleteActualOne removes an element only if it is contained in the collection

func (*Set[T]) DeleteOne

func (s *Set[T]) DeleteOne(element T)

DeleteOne removes an element from the collection

func (*Set[T]) Filt

func (s *Set[T]) Filt(filter func(T) (bool, error)) seq.SeqE[T]

Filt returns an errorable seq consisting of elements that satisfy the condition of the 'filter' function

func (*Set[T]) Filter

func (s *Set[T]) Filter(filter func(T) bool) seq.Seq[T]

Filter returns a seq that checks elements by the 'filter' function and returns successful ones.

func (*Set[T]) First

func (s *Set[T]) First(condition func(T) bool) (t T, ok bool)

First returns the element that satisfies the condition.

func (*Set[T]) ForEach

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

ForEach applies the 'consumer' function for every element

func (*Set[K]) HasAny

func (s *Set[K]) HasAny(condition func(K) bool) bool

HasAny checks whether the set contains an element that satisfies the condition.

func (*Set[T]) Head

func (s *Set[T]) Head() (t T, ok bool)

Head returns the first element.

func (*Set[T]) IsEmpty

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

IsEmpty returns true if the collection is empty

func (*Set[T]) Len

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

Len returns amount of the elements

func (*Set[T]) Reduce

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

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

func (*Set[T]) Slice

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

Slice collects the elements to a slice

func (*Set[T]) Sort

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

Sort transforms to the ordered Set contains sorted elements

func (*Set[T]) StableSort

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

StableSort transforms to the ordered Set contains sorted elements

func (*Set[T]) String

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

type Vector

type Vector[T any] []T

Vector is a collection implementation that provides elements order and index access

func NewVector

func NewVector[T any](elements ...T) *Vector[T]

NewVector instantiates Vector populated by the 'elements' slice

func NewVectorCap

func NewVectorCap[T any](capacity int) *Vector[T]

NewVectorCap instantiates Vector with a predefined capacity

func VectorFromSeq added in v0.0.15

func VectorFromSeq[T any](s seq.Seq[T]) *Vector[T]

VectorFromSeq creates a vector with elements retrieved by the seq.

func WrapVector

func WrapVector[T any](elements []T) *Vector[T]

WrapVector instantiates Vector using a slise as internal storage

func (*Vector[T]) Add

func (v *Vector[T]) Add(elements ...T)

Add adds elements to the end of the vector

func (*Vector[T]) AddAll

func (v *Vector[T]) AddAll(other seq.Seq[T])

AddAll inserts all elements from the "other" collection

func (*Vector[T]) AddOne

func (v *Vector[T]) AddOne(element T)

AddOne adds an element to the end of the vector

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

func (v *Vector[T]) All(consumer func(T) bool)

All is used to iterate through the collection using `for e := range`.

func (*Vector[T]) Append

func (v *Vector[T]) Append(out []T) []T

Append collects the values to the specified 'out' slice

func (*Vector[T]) Clone

func (v *Vector[T]) Clone() *Vector[T]

Clone just makes a copy of the vector instance

func (*Vector[T]) Conv

func (v *Vector[T]) Conv(converter func(T) (T, error)) seq.SeqE[T]

Conv returns an errorable seq that applies the 'converter' function to the collection elements

func (*Vector[T]) Convert

func (v *Vector[T]) Convert(converter func(T) T) seq.Seq[T]

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

func (*Vector[T]) Delete

func (v *Vector[T]) Delete(indexes ...int)

Delete drops elements by indexes

func (*Vector[T]) DeleteActual

func (v *Vector[T]) DeleteActual(indexes ...int) bool

DeleteActual drops elements by indexes with verification of no-op

func (*Vector[T]) DeleteActualOne

func (v *Vector[T]) DeleteActualOne(index int) bool

DeleteActualOne removes an element by the index

func (*Vector[T]) DeleteOne

func (v *Vector[T]) DeleteOne(index int)

DeleteOne removes an element by the index

func (*Vector[T]) Filt

func (v *Vector[T]) Filt(filter func(T) (bool, error)) seq.SeqE[T]

Filt returns an errorable seq consisting of elements that satisfy the condition of the 'filter' function

func (*Vector[T]) Filter

func (v *Vector[T]) Filter(filter func(T) bool) seq.Seq[T]

Filter returns a seq consisting of vector elements matching the filter

func (*Vector[T]) First

func (v *Vector[T]) First(condition func(T) bool) (t T, ok bool)

First returns the first element that satisfies requirements of the condition.

func (*Vector[T]) ForEach

func (v *Vector[T]) ForEach(consumer func(T))

ForEach applies consumer to elements without error checking

func (*Vector[T]) Get

func (v *Vector[T]) Get(index int) (t T, ok bool)

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

func (*Vector[T]) HasAny

func (v *Vector[T]) HasAny(condition func(T) bool) (ok bool)

HasAny checks whether the vector contains an element that satisfies the condition.

func (*Vector[T]) Head

func (v *Vector[T]) Head() (t T, ok bool)

Head returns the first element.

func (*Vector[T]) IAll added in v0.0.15

func (v *Vector[T]) IAll(consumer func(int, T) bool)

IAll is used to iterate through the collection using `for i, e := range`.

func (*Vector[T]) IsEmpty

func (v *Vector[T]) IsEmpty() bool

IsEmpty returns true if the collection is empty

func (*Vector[T]) Len

func (v *Vector[T]) Len() int

Len returns amount of elements

func (*Vector[T]) Reduce

func (v *Vector[T]) Reduce(merge func(T, T) T) (out T)

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

func (*Vector[T]) Remove

func (v *Vector[T]) Remove(index int) (t T, ok bool)

Remove removes and returns an element by the index

func (*Vector[T]) Set

func (v *Vector[T]) Set(index int, value T)

Set puts an element into the vector at the index

func (*Vector[T]) SetNew

func (v *Vector[T]) SetNew(index int, value T) bool

SetNew puts an element into the vector at the index

func (*Vector[T]) Slice

func (v *Vector[T]) Slice() (out []T)

Slice collects the elements to a slice

func (*Vector[T]) Sort

func (v *Vector[T]) Sort(comparer slice.Comparer[T]) *Vector[T]

Sort sorts the Vector in-place and returns it

func (*Vector[T]) StableSort

func (v *Vector[T]) StableSort(comparer slice.Comparer[T]) *Vector[T]

StableSort stable sorts the Vector in-place and returns it

func (*Vector[T]) String

func (v *Vector[T]) String() string

String returns then string representation

func (*Vector[T]) Tail

func (v *Vector[T]) Tail() (t T, ok bool)

Tail returns the latest element

func (*Vector[T]) TrackEach

func (v *Vector[T]) TrackEach(consumer func(int, T))

TrackEach applies consumer to elements without error checking

Directories

Path Synopsis
Package map_ provides unordered mutable.Map constructors
Package map_ provides unordered mutable.Map constructors
Package ordered provides mutable ordered collection implementations
Package ordered provides mutable ordered collection implementations
map_
Package map_ provides mutable ordered.Map constructors
Package map_ provides mutable ordered.Map constructors
set
Package set provides mutable github.com/m4gshm/gollections/collection/ordered.Set constructors and helpers
Package set provides mutable github.com/m4gshm/gollections/collection/ordered.Set constructors and helpers
Package set provides unordered github.com/m4gshm/gollections/collection/mutable.Set constructors and helpers
Package set provides unordered github.com/m4gshm/gollections/collection/mutable.Set constructors and helpers
Package sync provides parametrized Map implementation
Package sync provides parametrized Map implementation
Package vector provides mutable.Vector constructors and helpers
Package vector provides mutable.Vector constructors and helpers

Jump to

Keyboard shortcuts

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