Documentation
¶
Overview ¶
Package collection consists of common operations of Iterable based collections
Index ¶
- func Accum[IT c.Range[T], T any](first T, collection IT, merge func(T, T) T) T
- func Accumm[IT c.Range[T], T any](first T, collection IT, merge func(T, T) (T, error)) (T, error)
- func Conv[IT c.Range[From], From, To any](collection IT, converter func(From) (To, error)) seq.SeqE[To]
- func Convert[IT c.Range[From], From, To any](collection IT, converter func(From) To) seq.Seq[To]
- func ConvertNilSafe[IT c.Range[*From], From, To any](collection IT, converter func(*From) *To) seq.Seq[*To]
- func Filt[IT c.Range[T], T any](collection IT, filter func(T) (bool, error)) seq.SeqE[T]
- func Filter[IT c.Range[T], T any](collection IT, filter func(T) bool) seq.Seq[T]
- func FilterAndConvert[IT c.Range[From], From, To any](collection IT, filter func(From) bool, converter func(From) To) seq.Seq[To]
- func FilterAndFlat[IT c.Range[From], From, To any](collection IT, filter func(From) bool, flattener func(From) []To) seq.Seq[To]
- func First[IT c.Range[T], T any](collection IT, condition func(T) bool) (v T, ok bool)
- func Firstt[IT c.Range[T], T any](collection IT, condition func(T) (bool, error)) (v T, ok bool, err error)
- func Flat[IT c.Range[From], From, To any](collection IT, by func(From) []To) seq.Seq[To]
- func Flatt[IT c.Range[From], From, To any](collection IT, flattener func(From) ([]To, error)) seq.SeqE[To]
- func Head[IT c.Range[T], T any](collection IT) (T, bool)
- func IsEmpty[C interface{ ... }](collection C) bool
- 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]
- func NotNil[IT c.Range[*T], T any](collection IT) seq.Seq[*T]
- func Reduce[IT c.Range[T], T any](collection IT, merge func(T, T) T) T
- func Reducee[IT c.Range[T], T any](collection IT, merge func(T, T) (T, error)) (T, error)
- func Sort[SC any, Cmp ~func(T, T) int, C interface{ ... }, T any, O cmp.Ordered](collection C, order func(T) O) SC
- type Collection
- type Map
- type Seq
- type Seq2
- type SeqE
- type Set
- type Vector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Accum ¶ added in v0.0.13
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
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 ¶
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
Filt creates an erroreable iterator that iterates only those elements for which the 'filter' function returns true.
func Filter ¶
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 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 ¶
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 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 Reduce ¶ added in v0.0.13
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.
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
Seq is an iterator-function that allows to iterate over elements of a sequence, such as slice.
type Seq2 ¶ added in v0.0.17
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
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).
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 |