c

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 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).

func FitKey added in v0.0.5

func FitKey[K, V any](fit Predicate[K]) BiPredicate[K, V]

FitKey adapts a key appliable predicate to a key\value one

func FitValue added in v0.0.5

func FitValue[K, V any](fit Predicate[V]) BiPredicate[K, V]

FitValue adapts a value appliable predicate to a key\value one

type Binary added in v0.0.3

type Binary[T any] func(T, T) T

Binary is an operation with two arguments

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)
}

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

type IteratorBreakable added in v0.0.4

type IteratorBreakable[T any] interface {
	Iterator[T]
	//returns an iteration abort error
	Error() error
}

IteratorBreakable is the interface that provides iterate over elements of a source, where an iteration can be interrupted by an error.

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)
}

KVIterator is the interface that provides iterate over key/value pairs

type KVIteratorBreakable added in v0.0.5

type KVIteratorBreakable[K, V any] interface {
	KVIterator[K, V]
	//returns an iteration abort error
	Error() error
}

KVIteratorBreakable is the interface that provides iterate over key/value pairs, where an iteration can be interrupted by an error

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 Number added in v0.0.3

type Number interface {
	constraints.Integer | constraints.Float | constraints.Complex
}

Number is a type that supports the operators +, -, /, *

type Pipe

type Pipe[T any, Collection any] interface {
	Transformable[T, Collection]
	Container[Collection, Iterator[T]]
	Walk[T]
	WalkEach[T]
	Reduce(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 Quaternary added in v0.0.3

type Quaternary[t1, t2 any] func(t1, t2, t1, t2) (t1, t2)

Quaternary is an operation with four arguments

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 Sized added in v0.0.4

type Sized interface {
	// returns an estimated internal storage capacity or -1 if the capacity cannot be calculated
	Cap() int
}

Sized - storage interface with measurable capacity

type Summable added in v0.0.3

type Summable interface {
	constraints.Ordered | constraints.Complex
}

Summable is a type that supports the operator +

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
Package op consists of common operations of c.Iterable based collections
Package op consists of common operations of c.Iterable based collections

Jump to

Keyboard shortcuts

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