collection

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: May 5, 2023 License: MIT Imports: 11 Imported by: 3

Documentation

Overview

Package collection consists of common operations of c.Iterable based collections

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Conv

func Conv[From, To any, I c.Iterable[From]](collection I, converter func(From) (To, error)) breakStream.Iter[To]

Conv returns a breakable stream that applies the 'converter' function to the collection elements

func Convert

func Convert[From, To any, I c.Iterable[From]](collection I, converter func(From) To) stream.Iter[To]

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

func Filter

func Filter[T any, I c.Iterable[T]](collection I, filter func(T) bool) stream.Iter[T]

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

func FilterAndConvert

func FilterAndConvert[From, To any, I c.Iterable[From]](collection I, filter func(From) bool, converter func(From) To) stream.Iter[To]

FilterAndConvert returns a stream that filters source elements and converts them

func FilterAndFlatt

func FilterAndFlatt[From, To any, I c.Iterable[From]](collection I, filter func(From) bool, flattener func(From) []To) stream.Iter[To]

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

func First

func First[T any, I c.Iterable[T]](collection I, predicate func(T) bool) (v T, ok bool)

First returns the first element that satisfies the condition of the 'predicate' function

func Firstt

func Firstt[T any, I c.Iterable[T]](collection I, predicate func(T) (bool, error)) (v T, ok bool, err error)

Firstt returns the first element that satisfies the condition of the 'predicate' function

func Flat

func Flat[From, To comparable, I c.Iterable[From]](collection I, flattener func(From) ([]To, error)) breakStream.Iter[To]

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

func Flatt

func Flatt[From, To any, I c.Iterable[From]](collection I, by func(From) []To) stream.Iter[To]

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

func GetValues

func GetValues[T any, I c.Iterable[*T]](collection I) stream.Iter[T]

GetValues creates a stream that transform only not nil pointers to the values referenced referenced by those pointers. Nil pointers are ignored.

func Group

func Group[T any, K comparable, I c.Iterable[T]](collection I, by func(T) K) kvstream.Iter[K, T, map[K][]T]

Group groups elements to slices by a converter and returns a map

func NilSafe

func NilSafe[From, To any](next func() (*From, bool), converter func(*From) *To) stream.Iter[*To]

NilSafe - convert.NilSafe filters not nil next, converts that ones, filters not nils after converting and returns them

func NotNil

func NotNil[T any, I c.Iterable[*T]](collection I) stream.Iter[*T]

NotNil instantiates a stream that filters nullable elements

func ToValues

func ToValues[T any, I c.Iterable[*T]](collection I) stream.Iter[T]

ToValues creates a stream that transform pointers to the values referenced referenced by those pointers. Nil pointers are transformet to zero values.

Types

type Collection

type Collection[T any] interface {
	c.Collection[T]
	c.Filterable[T, stream.Iter[T], breakStream.Iter[T]]
	c.Convertable[T, stream.Iter[T], breakStream.Iter[T]]

	Len() int
	IsEmpty() bool

	HasAny(func(T) bool) 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, kvstream.Iter[K, V, map[K]V], breakKvstream.Iter[K, V, map[K]V]]
	kv.Convertable[K, V, kvstream.Iter[K, V, map[K]V], breakKvstream.Iter[K, V, map[K]V]]
	c.Checkable[K]
	c.Access[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 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.TrackLoop[int, T]
	c.TrackEachLoop[int, T]

	c.Access[int, T]
}

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

Directories

Path Synopsis
Package convert provides converation helpers for collection implementations
Package convert provides converation helpers for collection implementations
Package filter provides aliases for collections filtering helpers
Package filter provides aliases for collections filtering helpers
Package group provides short aliases for functions that are used to group collection elements
Package group provides short aliases for functions that are used to group collection elements
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 ordered.Set constructors and helpers
Package set provides ordered.Set constructors and helpers
set
Package set provides unordered immutable.Set constructors and helpers
Package set provides unordered 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 ordered.Set constructors and helpers
Package set provides mutable ordered.Set constructors and helpers
set
Package set provides unordered mutable.Set constructors and helpers
Package set provides unordered 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