c

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: MIT Imports: 2 Imported by: 3

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
var Break = errors.New("Break")

Break is the 'break' statement of the For, Track methods

Functions

This section is empty.

Types

type Access

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

Access 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)
	AddOne(T)
}

Addable provides appending the collection by elements.

type AddableAll added in v0.0.7

type AddableAll[Iterable any] interface {
	AddAll(Iterable)
}

AddableAll provides appending the collection by elements retrieved from another collection

type AddableAllNew added in v0.0.7

type AddableAllNew[Iterable any] interface {
	AddAllNew(Iterable) bool
}

AddableAllNew provides appending the collection by elements retrieved from another collection

type AddableNew added in v0.0.7

type AddableNew[T any] interface {
	AddNew(...T) bool
	AddOneNew(T) bool
}

AddableNew provides appending the collection by elements.

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] interface {
	For[T]
	ForEach[T]
	SliceFactory[T]

	Reduce(merger func(T, T) T) T
	HasAny(func(T) bool) bool
}

Collection is the base interface of non-associative collections

type Convertable added in v0.0.7

type Convertable[T any, Loop ~func() (T, bool), LoopErr ~func() (T, bool, error)] interface {
	Convert(converter func(T) T) Loop
	Conv(converter func(T) (T, error)) LoopErr
}

Convertable provides converaton of collection elements functionality

type DelIterator

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

DelIterator is the Iterator provides deleting of current element.

type Deleteable

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

Deleteable provides removing any elements from the collection.

type DeleteableVerify added in v0.0.7

type DeleteableVerify[k any] interface {
	DeleteActual(...k) bool
	DeleteActualOne(k) bool
}

DeleteableVerify provides removing any elements from the collection.

type Filterable added in v0.0.7

type Filterable[T any, Loop ~func() (T, bool), LoopErr ~func() (T, bool, error)] interface {
	Filter(predicate func(T) bool) Loop
	Filt(predicate func(T) (bool, error)) LoopErr
}

Filterable provides filtering content functionality

type For added in v0.0.12

type For[IT any] interface {
	//For takes elements of the collection. Can be interrupt by returning Break.
	For(func(element IT) error) error
}

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

type ForEach added in v0.0.12

type ForEach[T any] interface {
	// ForEach takes all elements of the collection
	ForEach(func(element T))
}

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

type ImmutableMapConvert added in v0.0.7

type ImmutableMapConvert[M any] interface {
	Immutable() M
}

ImmutableMapConvert provides converting to an immutable map instance.

type Iterable

type Iterable[T any, Loop ~func() (T, bool)] interface {
	Loop() Loop
}

Iterable is a loop supplier interface

type Iterator

type Iterator[T any] interface {
	// 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.
	Next() (out T, ok bool)

	For[T]
	ForEach[T]
	All(consumer func(T) bool)
}

Iterator 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 (KV[K, V]) Get added in v0.0.7

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

Get returns the key/value pair

func (KV[K, V]) Key

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

Key returns the key

func (KV[K, V]) Value

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

Value returns the value

type KeyVal added in v0.0.7

type KeyVal[Keys any, Vals any] interface {
	Keys() Keys
	Values() Vals
}

KeyVal provides extracing of a keys or values collection from key/value pairs

type MapFactory added in v0.0.7

type MapFactory[K comparable, V any, Map map[K]V | map[K][]V] interface {
	Map() Map
}

MapFactory collects the key/value pairs of the collection into a 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 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 provides removing an element by its pointer (index or key).

type Settable

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

Settable provides element insertion or replacement by its pointer (index or key).

type SettableMap added in v0.0.7

type SettableMap[Map any] interface {
	SetMap(m Map)
}

SettableMap provides element insertion or replacement with an equal key element of a map.

type SettableNew added in v0.0.7

type SettableNew[P any, V any] interface {
	SetNew(key P, value V) bool
}

SettableNew provides element insertion by its pointer (index or key) only if the specified place is not occupied.

type Sized added in v0.0.4

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

Sized - storage interface with measurable size

type SliceFactory added in v0.0.7

type SliceFactory[T any] interface {
	Slice() []T
	Append([]T) []T
}

SliceFactory collects the elements of the collection into a slice

type Summable added in v0.0.3

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

Summable is a type that supports the operator +

type Track

type Track[P any, T any] interface {
	// return Break for loop breaking
	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[P any, T 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

Jump to

Keyboard shortcuts

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