Documentation
¶
Index ¶
- Variables
- func Count[S ~[]T, T comparable](collection S, value T) (count int)
- func CountBy[S ~[]T, T comparable](collection S, predicates ...MorphCond2[int, T]) (count int)
- func Equal[S ~[]T, T comparable](c1 *Collection[S, T], c2 *Collection[S, T]) bool
- func EqualSlice[S ~[]T, T comparable](s1 S, s2 S) bool
- func Filter[S ~[]T, T comparable](collection S, mapping ...MorphCond2[int, T]) S
- func FilterSeq[S ~[]T, T comparable](collection S, mapping ...MorphCond2[int, T]) iter.Seq2[int, T]
- func ForEach[S ~[]T, T any](collection S, morph Morph0[T])
- func ForEachSeq[S ~[]T, T any](collection S) iter.Seq[T]
- func Map[S ~[]T, T, U any](collection S, mapping ...Morph2[int, T, U]) []U
- func MapSeq[S ~[]T, T, U any](collection S, mapping ...Morph2[int, T, U]) iter.Seq2[int, U]
- func Unique[S ~[]T, T comparable](collection S, mapping ...Morph[T, T]) S
- func UniqueSeq[S ~[]T, T comparable](collection S, mapping ...Morph[T, T]) iter.Seq[T]
- type Collection
- func (c *Collection[S, T]) Append(value ...T) error
- func (c *Collection[S, T]) Cap() int
- func (c *Collection[S, T]) Get(ind int) (T, error)
- func (c *Collection[S, T]) Len() int
- func (c *Collection[S, T]) ReadOnly() bool
- func (c *Collection[S, T]) Set(ind int, value T) error
- func (c *Collection[S, T]) Unwrap() S
- type Morph
- type Morph0
- type Morph2
- type MorphCond
- type MorphCond2
Constants ¶
This section is empty.
Variables ¶
var ( ErrReadOnlyCollection = fmt.Errorf("collection is read only") ErrIndexOutOfRaange = fmt.Errorf("index for collection assign is out of range") )
Functions ¶
func Count ¶
func Count[S ~[]T, T comparable](collection S, value T) (count int)
Count returns the number of elements in the slice that are equal to the specified value.
func CountBy ¶
func CountBy[S ~[]T, T comparable](collection S, predicates ...MorphCond2[int, T]) (count int)
CountBy returns the number of elements in the slice that satisfy the given predicate(s).
It uses MorphCond2 transformations, allowing for operations like:
CountBy([]Type{...}, func(index int, value Type) bool {...})
func Equal ¶
func Equal[S ~[]T, T comparable](c1 *Collection[S, T], c2 *Collection[S, T]) bool
func EqualSlice ¶
func EqualSlice[S ~[]T, T comparable](s1 S, s2 S) bool
func Filter ¶
func Filter[S ~[]T, T comparable](collection S, mapping ...MorphCond2[int, T]) S
Filter returns a new slice containing only the elements that satisfy the given predicate(s).
It uses MorphCond transformations, allowing for operations like:
Filter([]Type{...}, func(value Type) bool {...})
func FilterSeq ¶
func FilterSeq[S ~[]T, T comparable](collection S, mapping ...MorphCond2[int, T]) iter.Seq2[int, T]
FilterSeq returns an iterator (Seq) that yields elements from the input slice that satisfy the given predicate(s).
func ForEach ¶
ForEach applies a function to each element in the input slice.
It uses Morph0 transformations, allowing for operations like:
ForEach([]Type{...}, func(value Type) {...})
func ForEachSeq ¶
ForEachSeq returns an iterator (Seq) that yields each element in the input slice, allowing for operations to be performed on each element.
func Map ¶
Map transforms a slice of one type into a slice of another type.
It uses Morph2 transformations, allowing for operations like:
Map([]Type{...}, func(index int, value Type) NewType {...})
func MapSeq ¶
MapSeq returns an iterator (Seq2) that applies a series of transformations to each element in the input slice.
func Unique ¶
func Unique[S ~[]T, T comparable](collection S, mapping ...Morph[T, T]) S
Unique returns a new slice containing only the unique elements from the input slice, with optional transformations.
Types ¶
type Collection ¶
type Collection[S ~[]T, T any] struct { // contains filtered or unexported fields }
func NewCollection ¶
func NewCollection[S ~[]T, T any](slice S, readOnly bool) *Collection[S, T]
func (*Collection[S, T]) Append ¶
func (c *Collection[S, T]) Append(value ...T) error
func (*Collection[S, T]) Cap ¶
func (c *Collection[S, T]) Cap() int
func (*Collection[S, T]) Get ¶
func (c *Collection[S, T]) Get(ind int) (T, error)
func (*Collection[S, T]) Len ¶
func (c *Collection[S, T]) Len() int
func (*Collection[S, T]) ReadOnly ¶
func (c *Collection[S, T]) ReadOnly() bool
func (*Collection[S, T]) Set ¶
func (c *Collection[S, T]) Set(ind int, value T) error
func (*Collection[S, T]) Unwrap ¶
func (c *Collection[S, T]) Unwrap() S
type Morph ¶
type Morph[CurrentType, NewType any] func(CurrentType) NewType
Morph is a CurrentType to NewType transformation.
type Morph0 ¶
type Morph0[CurrentType any] func(CurrentType)
Morph0 is a static transformation of CurrentType.
type Morph2 ¶
type Morph2[KeyType, ValueType, NewValueType any] func(KeyType, ValueType) NewValueType
Morph2 is a KeyType and ValueType to NewValueType transformation.
type MorphCond ¶
type MorphCond[T comparable] func(T) bool
MorphCond is a conditional transformation of T-type.
type MorphCond2 ¶
type MorphCond2[K, V comparable] func(K, V) bool
MorphCond2 is a conditional transformation of K-type and T-type.