immutable

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: 21 Imported by: 2

Documentation

Overview

Package immutable provides immutable collection 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 an map using key/value pairs

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]) 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)) breakKvStream.Iter[K, V, map[K]V]

Conv returns a breakable stream 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)) breakKvStream.Iter[K, V, map[K]V]

ConvKey returns a stream 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)) breakKvStream.Iter[K, V, map[K]V]

ConvValue returns a stream 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)) stream.Iter[K, V, map[K]V]

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

func (Map[K, V]) ConvertKey

func (m Map[K, V]) ConvertKey(by func(K) K) stream.Iter[K, V, map[K]V]

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

func (Map[K, V]) ConvertValue

func (m Map[K, V]) ConvertValue(by func(V) V) stream.Iter[K, V, map[K]V]

ConvertValue returns a stream 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)) breakKvStream.Iter[K, V, map[K]V]

Filt returns a breakable stream 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)) breakKvStream.Iter[K, V, map[K]V]

FiltKey returns a stream 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)) breakKvStream.Iter[K, V, map[K]V]

FiltValue returns a stream 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) stream.Iter[K, V, map[K]V]

Filter returns a stream 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) stream.Iter[K, V, map[K]V]

FilterKey returns a stream 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) stream.Iter[K, V, map[K]V]

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

func (Map[K, V]) First

func (m Map[K, V]) First() (map_.Iter[K, V], K, V, bool)

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

func (m Map[K, V]) For(walker func(c.KV[K, V]) error) error

For applies the 'walker' function for every key/value pair. Return the c.ErrBreak to stop.

func (Map[K, V]) ForEach

func (m Map[K, V]) ForEach(walker func(c.KV[K, V]))

ForEach applies the 'walker' function for every key/value pair

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

func (m Map[K, V]) Head() map_.Iter[K, V]

Head creates an iterator and returns as implementation type value

func (Map[K, V]) IsEmpty

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

IsEmpty returns true if the map is empty

func (Map[K, V]) Iter

func (m Map[K, V]) Iter() kv.Iterator[K, V]

Iter creates an iterator and returns as interface

func (Map[K, V]) K

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

K resutrns keys collection impl

func (Map[K, V]) Keys

func (m Map[K, V]) Keys() 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]) Loop

func (m Map[K, V]) Loop() *map_.Iter[K, V]

Loop creates an iterator and returns as implementation type reference

func (Map[K, V]) Map

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

Map collects the key/value pairs to a 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(less slice.Less[K]) ordered.Map[K, V]

Sort sorts the keys

func (Map[K, V]) StableSort

func (m Map[K, V]) StableSort(less slice.Less[K]) ordered.Map[K, V]

StableSort sorts the keys

func (Map[K, V]) String

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

func (Map[K, V]) Track

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

Track applies the 'tracker' function for key/value pairs. Return the c.ErrBreak to stop.

func (Map[K, V]) TrackEach

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

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

func (Map[K, V]) V

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

V resutrns values collection impl

func (Map[K, V]) Values

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

Values resutrns values collection

type MapKeys

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

MapKeys is the container reveal keys of a map and hides values

func WrapKeys

func WrapKeys[K comparable, V any](elements map[K]V) MapKeys[K, V]

WrapKeys instantiates MapKeys using the elements as internal storage

func (MapKeys[K, V]) Append

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

Append collects the values to the specified 'out' slice

func (MapKeys[K, V]) Conv

func (m MapKeys[K, V]) Conv(converter func(K) (K, error)) breakStream.Iter[K]

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

func (MapKeys[K, V]) Convert

func (m MapKeys[K, V]) Convert(converter func(K) K) stream.Iter[K]

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

func (MapKeys[K, V]) Filt

func (m MapKeys[K, V]) Filt(predicate func(K) (bool, error)) breakStream.Iter[K]

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

func (MapKeys[K, V]) Filter

func (m MapKeys[K, V]) Filter(filter func(K) bool) stream.Iter[K]

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

func (MapKeys[K, V]) First

func (m MapKeys[K, V]) First() (map_.KeyIter[K, V], K, bool)

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, V]) For

func (m MapKeys[K, V]) For(walker func(K) error) error

For applies the 'walker' function for every key. Return the c.ErrBreak to stop.

func (MapKeys[K, V]) ForEach

func (m MapKeys[K, V]) ForEach(walker func(K))

ForEach applies the 'walker' function for every key

func (MapKeys[K, V]) HasAny

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

func (m MapKeys[K, V]) Head() map_.KeyIter[K, V]

Head creates an iterator and returns as implementation type value

func (MapKeys[K, V]) IsEmpty

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

IsEmpty returns true if the collection is empty

func (MapKeys[K, V]) Iter

func (m MapKeys[K, V]) Iter() c.Iterator[K]

Iter creates an iterator and returns as interface

func (MapKeys[K, V]) Len

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

Len returns amount of elements

func (MapKeys[K, V]) Loop

func (m MapKeys[K, V]) Loop() *map_.KeyIter[K, V]

Loop creates an iterator and returns as implementation type reference

func (MapKeys[K, V]) Reduce

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

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

func (MapKeys[K, V]) Slice

func (m MapKeys[K, V]) Slice() []K

Slice collects the elements to a slice

func (MapKeys[K, V]) String

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

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

WrapVal instantiates MapValues using elements as internal storage.

func (MapValues[K, V]) Append

func (m MapValues[K, V]) Append(out []V) []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)) breakStream.Iter[V]

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

func (MapValues[K, V]) Convert

func (m MapValues[K, V]) Convert(converter func(V) V) stream.Iter[V]

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

func (MapValues[K, V]) Filt

func (m MapValues[K, V]) Filt(predicate func(V) (bool, error)) breakStream.Iter[V]

Filt returns a breakable stream 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) stream.Iter[V]

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

func (MapValues[K, V]) First

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

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(walker func(V) error) error

For applies the 'walker' function for collection values. Return the c.ErrBreak to stop.

func (MapValues[K, V]) ForEach

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

ForEach applies the 'walker' function for every value of the collection

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

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

Head creates an iterator and returns as implementation type value

func (MapValues[K, V]) IsEmpty

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

IsEmpty returns true if the collection is empty

func (MapValues[K, V]) Iter

func (m MapValues[K, V]) Iter() c.Iterator[V]

Iter creates an iterator and returns as interface

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() *map_.ValIter[K, V]

Loop creates an iterator and returns as implementation type reference

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() []V

Slice collects the values to a slice

func (MapValues[K, V]) Sort

func (m MapValues[K, V]) Sort(less func(e1, e2 V) bool) Vector[V]

Sort creates a vector with sorted the values

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. 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](elements map[T]struct{}) Set[T]

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

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)) breakStream.Iter[T]

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

func (Set[T]) Convert

func (s Set[T]) Convert(converter func(T) T) stream.Iter[T]

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

func (Set[T]) Filt

func (s Set[T]) Filt(predicate func(T) (bool, error)) breakStream.Iter[T]

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

func (Set[T]) Filter

func (s Set[T]) Filter(predicate func(T) bool) stream.Iter[T]

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

func (Set[T]) First

func (s Set[T]) First() (map_.KeyIter[T, struct{}], T, bool)

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(walker func(T) error) error

For applies the 'walker' function for the elements. Return the c.ErrBreak to stop.

func (Set[T]) ForEach

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

ForEach applies the 'walker' 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

func (s Set[T]) Head() map_.KeyIter[T, struct{}]

Head creates an iterator and returns as implementation type value

func (Set[T]) IsEmpty

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

IsEmpty returns true if the collection is empty

func (Set[T]) Iter

func (s Set[T]) Iter() c.Iterator[T]

Iter creates an iterator and returns as interface

func (Set[T]) Len

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

Len returns amount of elements

func (Set[T]) Loop

func (s Set[T]) Loop() *map_.KeyIter[T, struct{}]

Loop creates an iterator and returns as implementation type reference

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(less slice.Less[T]) ordered.Set[T]

Sort transforms to the ordered set with sorted elements

func (Set[T]) StableSort

func (s Set[T]) StableSort(less slice.Less[T]) ordered.Set[T]

StableSort transforms to the ordered set with sorted elements

func (Set[T]) String

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

type Vector

type Vector[T any] struct {
	// contains filtered or unexported fields
}

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 VectorFromLoop

func VectorFromLoop[T any](next func() (T, bool)) Vector[T]

VectorFromLoop creates a vector 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 WrapVector

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

WrapVector instantiates Vector using a slise as internal storage.

func (Vector[T]) Append

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

Append collects the values to the specified 'out' slice

func (Vector[T]) Conv

func (v Vector[T]) Conv(converter func(T) (T, error)) breakStream.Iter[T]

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

func (Vector[T]) Convert

func (v Vector[T]) Convert(converter func(T) T) stream.Iter[T]

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

func (Vector[T]) Filt

func (v Vector[T]) Filt(predicate func(T) (bool, error)) breakStream.Iter[T]

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

func (Vector[T]) Filter

func (v Vector[T]) Filter(filter func(T) bool) stream.Iter[T]

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

func (Vector[T]) First

func (v Vector[T]) First() (slice.Iter[T], T, bool)

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 (Vector[T]) For

func (v Vector[T]) For(walker func(T) error) error

For applies the 'walker' function for the elements. Return the c.ErrBreak to stop.

func (Vector[T]) ForEach

func (v Vector[T]) ForEach(walker func(T))

ForEach applies the 'walker' function for every element

func (Vector[T]) Get

func (v Vector[T]) Get(index int) (out 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(predicate func(T) bool) bool

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

func (Vector[T]) Head

func (v Vector[T]) Head() slice.Iter[T]

Head creates an iterator and returns as implementation type value

func (Vector[T]) IsEmpty

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

IsEmpty returns true if the collection is empty

func (Vector[T]) Iter

func (v Vector[T]) Iter() c.Iterator[T]

Iter creates an iterator and returns as interface

func (Vector[T]) Last

func (v Vector[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 (Vector[T]) Len

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

Len returns amount of elements

func (Vector[T]) Loop

func (v Vector[T]) Loop() *slice.Iter[T]

Loop creates an iterator and returns as implementation type reference

func (Vector[T]) Reduce

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

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

func (Vector[T]) Slice

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

Slice collects the elements to a slice

func (Vector[T]) Sort

func (v Vector[T]) Sort(less slice.Less[T]) Vector[T]

Sort returns a sorted clone of the Vector

func (Vector[T]) StableSort

func (v Vector[T]) StableSort(less slice.Less[T]) Vector[T]

StableSort returns a stable sorted clone of the Vector

func (Vector[T]) String

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

func (Vector[T]) Tail

func (v Vector[T]) Tail() slice.Iter[T]

Tail creates an iterator pointing to the end of the collection

func (Vector[T]) Track

func (v Vector[T]) Track(tracker func(int, T) error) error

Track applies the 'tracker' function for elements. Return the c.ErrBreak to stop.

func (Vector[T]) TrackEach

func (v Vector[T]) TrackEach(tracker func(int, T))

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

Directories

Path Synopsis
Package map_ provides immutable.Map constructors
Package map_ provides immutable.Map constructors
Package ordered provides immutable ordered collection implementations
Package ordered provides immutable ordered collection implementations
map_
Package map_ provides immutale ordered.Map constructors
Package map_ provides immutale ordered.Map constructors
set
Package set provides ordered.Set constructors and helpers
Package set provides ordered.Set constructors and helpers
Package set provides unordered immutable.Set constructors and helpers
Package set provides unordered immutable.Set constructors and helpers
Package vector provides ordered immutable.Vector constructors and helpers
Package vector provides ordered immutable.Vector constructors and helpers

Jump to

Keyboard shortcuts

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