c

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2022 License: MIT Imports: 1 Imported by: 1

Documentation

Overview

Package c provides common types of containers, utility types and functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Access

type Access[P any, V any] interface {
	Get(P) (V, bool)
}

Access is the interface that provides access to an element by its pointer (index, key, coordinate, etc.) Where:

P - a type of pointer to a value (index, map key, coordinates)
V - any arbitrary type of the value

type Addable

type Addable[T any] interface {
	Add(...T) bool
}

Addable is the interface that provides appending the collection by elements.

type BiConverter

type BiConverter[From1, From2, To1, To2 any] func(From1, From2) (To1, To2)

BiConverter convert pairs of From -> To.

type BiPredicate

type BiPredicate[v1, v2 any] func(v1, v2) bool

BiPredicate tests values pair (converts to true or false).

type Checkable

type Checkable[T any] interface {
	Contains(T) bool
}

Checkable is container with ability to check if an element is present.

type Collection

type Collection[T any, Collection any, IT any] interface {
	Container[Collection, IT]
	Walk[T]
	WalkEach[T]
	Len() int
	IsEmpty() bool
}

Collection is the interface of a finite-size container. Where:

T - any arbitrary type
Collection - a collection type (may be slice, map or chain)
IT - a iterator type  (Iterator, KVIterator)

type Container

type Container[Collection any, IT any] interface {
	Collect() Collection
	Iterable[IT]
}

Container is the base interface of implementations. Where:

Collection - a collection type (may be slice, map or chain)
IT - a iterator type  (Iterator, KVIterator)

type Converter

type Converter[From, To any] func(From) To

Converter convert From -> To.

type DelIterator

type DelIterator[T any] interface {
	Iterator[T]
	Delete() bool
}

DelIterator is the Iterator provides deleting of current element.

type Deleteable

type Deleteable[k any] interface {
	Delete(...k) bool
}

Deleteable is the interface that provides removing any elements from the collection.

type Flatter

type Flatter[From, To any] Converter[From, []To]

Flatter extracts slice of To.

type Iterable

type Iterable[IT any] interface {
	Begin() IT
}

Iterable is an iterator supplier interface

type Iterator

type Iterator[T any] interface {
	//retrieves a next element and true or zero value of T and false if no more elements.
	Next() (T, bool)
	//returns an estimated internal storage capacity
	Cap() int
}

Iterator is the interface that provides iterate over elements of a collection.

type KV

type KV[k any, v any] struct {
	K k
	V v
}

KV is the simplest implementation of a key/value pair.

func NewKV

func NewKV[K any, V any](key K, value V) KV[K, V]

NewKV creates a key/value pair holder.

func (KV[K, V]) GetNext

func (k KV[K, V]) GetNext() (K, V)

func (KV[K, V]) Key

func (k KV[K, V]) Key() K

func (KV[K, V]) Value

func (k KV[K, V]) Value() V

type KVIterator

type KVIterator[K, V any] interface {
	//retrieves next elements or zero values if no more elements
	Next() (K, V, bool)
	Cap() int
}

KVIterator is the interface that provides iterate over all key/value pair of a map.

type Map

type Map[K comparable, V any] interface {
	Collection[KV[K, V], map[K]V, KVIterator[K, V]]
	Track[V, K]
	TrackEach[V, K]
	Checkable[K]
	Access[K, V]
	MapTransformable[K, V, map[K]V]
	Keys() Collection[K, []K, Iterator[K]]
	Values() Collection[V, []V, Iterator[V]]
}

Map - collection interface that stores key/value pairs and provide access to an element by its key.

type MapPipe

type MapPipe[K comparable, V any, Map any] interface {
	MapTransformable[K, V, Map]
	Container[Map, KVIterator[K, V]]
}

MapPipe extends MapTransformable by finalize methods like ForEach, Collect or Reduce.

type MapTransformable

type MapTransformable[K comparable, V any, Map any] interface {
	Filter(BiPredicate[K, V]) MapPipe[K, V, Map]
	Map(BiConverter[K, V, K, V]) MapPipe[K, V, Map]

	FilterKey(Predicate[K]) MapPipe[K, V, Map]
	MapKey(Converter[K, K]) MapPipe[K, V, Map]

	FilterValue(Predicate[V]) MapPipe[K, V, Map]
	MapValue(Converter[V, V]) MapPipe[K, V, Map]
}

MapTransformable is the interface that provides limited kit of map transformation methods. The full kit of transformer functions are in the package 'c/map_'

type Pipe

type Pipe[T any, Collection any] interface {
	Transformable[T, Collection]
	Container[Collection, Iterator[T]]
	Walk[T]
	WalkEach[T]
	Reduce(op.Binary[T]) T
}

Pipe extends Transformable by finalize methods like ForEach, Collect or Reduce.

type Predicate

type Predicate[T any] func(T) bool

Predicate tests value (converts to true or false).

type PrevIterator

type PrevIterator[T any] interface {
	Iterator[T]
	//retrieves a prev element and true or zero value of T and false if no more elements.
	Prev() (T, bool)
}

PrevIterator is the Iterator that provides reverse iteration over elements of a collection.

type Removable

type Removable[P any, V any] interface {
	Remove(P) (V, bool)
}

Removable is the interface that provides removing an element by its pointer (index or key).

type Set

type Set[T any] interface {
	Collection[T, []T, Iterator[T]]
	Transformable[T, []T]
	Checkable[T]
}

Set - collection interface that ensures the uniqueness of elements (does not insert duplicate values).

type Settable

type Settable[P any, V any] interface {
	Set(key P, value V) bool
}

Settable is the interface that provides replacing an element by its pointer (index or key).

type Track

type Track[T any, P any] interface {
	Track(func(position P, element T) error) error
}

Track is the interface of a collection that provides traversing of the elements with position tracking (index, key, coordinates, etc.).

type TrackEach

type TrackEach[T any, P any] interface {
	TrackEach(func(position P, element T))
}

TrackEach is the interface of a collection that provides traversing of the elements with position tracking (index, key, coordinates, etc.) without error checking

type Transformable

type Transformable[T any, Collection any] interface {
	Filter(Predicate[T]) Pipe[T, Collection]
	Map(Converter[T, T]) Pipe[T, Collection]
}

Transformable is the interface that provides limited kit of container transformation methods. The full kit of transformer functions are in the package 'c'

type Vector

type Vector[T any] interface {
	Collection[T, []T, Iterator[T]]
	Track[T, int]
	TrackEach[T, int]
	Access[int, T]
	Transformable[T, []T]
}

Vector - collection interface that provides elements order and access by index to the elements.

type Walk

type Walk[IT any] interface {
	For(func(element IT) error) error
}

Walk is the interface of a collection that provides traversing of the elements.

type WalkEach

type WalkEach[T any] interface {
	ForEach(func(element T))
}

WalkEach is the interface of a collection that provides traversing of the elements without error checking.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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