collection

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: 6 Imported by: 1

Documentation

Overview

Package collection consists of common operations of Iterable based collections

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Accum added in v0.0.13

func Accum[IT c.Range[T], T any](first T, collection IT, merge func(T, T) T) T

Accum accumulates a value by using the 'first' argument to initialize the accumulator and sequentially applying the 'merge' functon to the accumulator and each element of the 'collection'.

func Accumm added in v0.0.13

func Accumm[IT c.Range[T], T any](first T, collection IT, merge func(T, T) (T, error)) (T, error)

Accumm accumulates a value by using the 'first' argument to initialize the accumulator and sequentially applying the 'merge' functon to the accumulator and each element of the 'collection'.

func Conv

func Conv[IT c.Range[From], From, To any](collection IT, converter func(From) (To, error)) seq.SeqE[To]

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

func Convert

func Convert[IT c.Range[From], From, To any](collection IT, converter func(From) To) seq.Seq[To]

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

func ConvertNilSafe added in v0.0.17

func ConvertNilSafe[IT c.Range[*From], From, To any](collection IT, converter func(*From) *To) seq.Seq[*To]

ConvertNilSafe creates a seq that filters not nil elements, converts that ones, filters not nils after converting and returns them

func Filt added in v0.0.17

func Filt[IT c.Range[T], T any](collection IT, filter func(T) (bool, error)) seq.SeqE[T]

Filt creates an erroreable iterator that iterates only those elements for which the 'filter' function returns true.

func Filter

func Filter[IT c.Range[T], T any](collection IT, filter func(T) bool) seq.Seq[T]

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

func FilterAndConvert

func FilterAndConvert[IT c.Range[From], From, To any](collection IT, filter func(From) bool, converter func(From) To) seq.Seq[To]

FilterAndConvert returns a seq that filters source elements and converts them

func FilterAndFlat added in v0.0.9

func FilterAndFlat[IT c.Range[From], From, To any](collection IT, filter func(From) bool, flattener func(From) []To) seq.Seq[To]

FilterAndFlat filters source elements and extracts slices of 'To' by the 'flattener' function

func First

func First[IT c.Range[T], T any](collection IT, condition func(T) bool) (v T, ok bool)

First returns the first element that satisfies the condition.

func Firstt

func Firstt[IT c.Range[T], T any](collection IT, condition func(T) (bool, error)) (v T, ok bool, err error)

Firstt returns the first element that satisfies the condition.

func Flat

func Flat[IT c.Range[From], From, To any](collection IT, by func(From) []To) seq.Seq[To]

Flat returns a seq that converts the collection elements into slices and then flattens them to one level

func Flatt

func Flatt[IT c.Range[From], From, To any](collection IT, flattener func(From) ([]To, error)) seq.SeqE[To]

Flatt returns an errorable seq that converts the collection elements into slices and then flattens them to one level

func Head[IT c.Range[T], T any](collection IT) (T, bool)

Head returns the first element.

func IsEmpty added in v0.0.15

func IsEmpty[C interface{ Len() int }](collection C) bool

IsEmpty returns true if the collection is empty

func KeyValue added in v0.0.10

func KeyValue[IT c.Range[T], T any, K comparable, V any](collection IT, keyExtractor func(T) K, valExtractor func(T) V) seq.Seq2[K, V]

KeyValue transforms iterable elements to key/value iterator based on applying key, value extractors to the elements

func NotNil

func NotNil[IT c.Range[*T], T any](collection IT) seq.Seq[*T]

NotNil instantiates a seq that filters nullable elements

func Reduce added in v0.0.13

func Reduce[IT c.Range[T], T any](collection IT, merge func(T, T) T) T

Reduce reduces the 'collection' elements into an one using the 'merge' function. If the 'collection' is empty, the zero value of 'T' type is returned.

func Reducee added in v0.0.13

func Reducee[IT c.Range[T], T any](collection IT, merge func(T, T) (T, error)) (T, error)

Reducee reduces the 'collection' elements into an one using the 'merge' function. Returns ok==false if the 'collection' is empty.

func Sort added in v0.0.8

func Sort[SC any, Cmp ~func(T, T) int, C interface {
	Sort(Cmp) SC
}, T any, O cmp.Ordered](collection C, order func(T) O) SC

Sort sorts the specified sortable collection that contains orderable elements

Types

type Collection

type Collection[T any] interface {
	c.Collection[T]
	c.Filterable[T, seq.Seq[T], seq.SeqE[T]]
	c.Convertable[T, seq.Seq[T], seq.SeqE[T]]

	Len() int
	IsEmpty() bool
}

Collection is the base interface for the Vector and the Set impelementations

type Map

type Map[K comparable, V any] interface {
	kv.Collection[K, V, map[K]V]
	kv.Filterable[K, V, seq.Seq2[K, V], seq.SeqE[c.KV[K, V]]]
	kv.Convertable[K, V, seq.Seq2[K, V], seq.SeqE[c.KV[K, V]]]
	c.Checkable[K]
	c.Access[K, V]
	c.KVRange[K, V]

	Len() int
	IsEmpty() bool

	HasAny(func(K, V) bool) bool
}

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

type Seq added in v0.0.17

type Seq[T any] func(yield func(T) bool)

Seq is an iterator-function that allows to iterate over elements of a sequence, such as slice.

type Seq2 added in v0.0.17

type Seq2[K, V any] func(yield func(K, V) bool)

Seq2 is an iterator-function that allows to iterate over key/value pairs of a sequence, such as slice or map. It is used to iterate over slice index/value pairs or map key/value pairs.

type SeqE added in v0.0.17

type SeqE[T any] func(yield func(T, error) bool)

SeqE is a specific iterator form that allows to retrieve a value with an error as second parameter of the iterator. It is used as a result of applying functions like seq.Conv, which may throw an error during iteration. At each iteration step, it is necessary to check for the occurrence of an error.

for e, err := range seqence {
    if err != nil {
        break
    }
    ...
}

type Set

type Set[T comparable] interface {
	Collection[T]
	c.Checkable[T]
}

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

type Vector

type Vector[T any] interface {
	Collection[T]
	c.TrackEach[int, T]
	c.Access[int, T]
}

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

Directories

Path Synopsis
Package immutable provides immutable collection implementations
Package immutable provides immutable collection implementations
map_
Package map_ provides immutable.Map constructors
Package map_ provides immutable.Map constructors
ordered
Package ordered provides immutable ordered collection implementations
Package ordered provides immutable ordered collection implementations
ordered/map_
Package map_ provides immutale ordered.Map constructors
Package map_ provides immutale ordered.Map constructors
ordered/set
Package set provides github.com/m4gshm/gollections/collection/ordered.Set constructors and helpers
Package set provides github.com/m4gshm/gollections/collection/ordered.Set constructors and helpers
set
Package set provides unordered github.com/m4gshm/gollections/collection/immutable.Set constructors and helpers
Package set provides unordered github.com/m4gshm/gollections/collection/immutable.Set constructors and helpers
vector
Package vector provides ordered immutable.Vector constructors and helpers
Package vector provides ordered immutable.Vector constructors and helpers
Package mutable provides implementations of mutable containers.
Package mutable provides implementations of mutable containers.
map_
Package map_ provides unordered mutable.Map constructors
Package map_ provides unordered mutable.Map constructors
ordered
Package ordered provides mutable ordered collection implementations
Package ordered provides mutable ordered collection implementations
ordered/map_
Package map_ provides mutable ordered.Map constructors
Package map_ provides mutable ordered.Map constructors
ordered/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
set
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
sync
Package sync provides parametrized Map implementation
Package sync provides parametrized Map implementation
vector
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