collections

package
v0.0.0-...-11759f2 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Asc

func Asc[L ~[]V, V constraints.Ordered](list L)

Asc is sorting the elements of a slice `list` in ascending order.

func ConstainsF

func ConstainsF[L ~[]V, V any](list L, v V, comp function.BiPredicate[V, V]) bool

ConstainsF returns a boolean value indicating whether there is an element in `list` for which `comp` returns `true` when called with `v` and that element as arguments.

func Contains

func Contains[L ~[]V, V comparable](list L, v V) bool

Contains returns a boolean value indicating whether `v` is present in the slice `list`.

func ContainsAny

func ContainsAny[L ~[]V, V comparable](list L, values ...V) bool

ContainsAny returns a boolean value indicating whether any of the values passed as arguments are present in the slice `list`.

func ContainsAnyF

func ContainsAnyF[L ~[]V, V any](list L, comp function.BiPredicate[V, V], values ...V) bool

ContainsAnyF returns a boolean value indicating whether there is an element in `list` for which `comp` returns `true` when called with `v` and that element as arguments, where `v` is any of the values passed as arguments in `values`.

func Desc

func Desc[L ~[]V, V constraints.Ordered](list L)

Desc is sorting the elements of a slice `list` in descending order.

func Distinct

func Distinct[L ~[]V, V comparable](list L) L

Distinct returns a new slice of type `L` containing only the distinct elements of `list`.

func DistinctF

func DistinctF[L ~[]V, V any](list L, comp function.BiPredicate[V, V]) L

DistinctF returns a new slice of type `L` containing only the distinct elements of `list`, where distinct means that no two elements are equal according to the `comp` function.

func Filter

func Filter[L ~[]V, V any](list L, pred function.Predicate[V]) L

Filter returns a new slice of type `L` containing only the elements of `list` for which `pred` returns `true`.

func ForEach

func ForEach[L ~[]V, V any](list L, consumer function.Consumer[V])

ForEach performing a loop over the elements of the slice and applying a function to each element.

func GetEntrySet

func GetEntrySet[M ~map[K]V, S EntrySet[K, V], K comparable, V any](m M) S

func Keys

func Keys[M ~map[K]V, K comparable, V any](m M) []K

func Map

func Map[LI ~[]I, LO []O, I, O any](in LI, mapper function.Func[I, O]) LO

Map returns a new slice of type `LO` containing the result of applying the `mapper` function to each element of the input slice `in`.

func Sort

func Sort[L ~[]V, V any](list L, less func(i, j V) bool)

Sort is sorting the elements of a slice `list` of type `L` containing elements of type `V`, where `V` can be any type.

func Values

func Values[M ~map[K]V, K comparable, V any](m M) []V

Types

type Entry

type Entry[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func (Entry[K, V]) Key

func (en Entry[K, V]) Key() K

func (Entry[K, V]) Value

func (en Entry[K, V]) Value() V

type EntrySet

type EntrySet[K comparable, V any] []Entry[K, V]

func ConvertToEntrySet

func ConvertToEntrySet[S ~[]Entry[K, V], K comparable, V any](s S) EntrySet[K, V]

func (EntrySet[K, V]) Keys

func (set EntrySet[K, V]) Keys() []K

func (EntrySet[K, V]) List

func (set EntrySet[K, V]) List() []Entry[K, V]

func (EntrySet[K, V]) Values

func (set EntrySet[K, V]) Values() []V

type Iterator

type Iterator[T any] interface {
	HasNext() bool
	Next() T
	ForEachRemaining(function.Consumer[T])
}

func Iterable

func Iterable[T any](iter iterator[T]) Iterator[T]

func IterableChan

func IterableChan[T any](ch chan T) Iterator[T]

func IterableSlice

func IterableSlice[T any](list ...T) Iterator[T]

type Set

type Set[T any] interface {
	// Elements returns a slice containing all elements in the set.
	Elements() []T
	// Size returns the number of elements in the set.
	Size() int
	// Clear removes all elements from the set.
	Clear()
	// Add adds an element to the set.
	Add(element ...T) Set[T]
	// Remove removes an element from the set.
	Remove(element ...T) Set[T]
	// Contains checks if the set contains a specific element.
	Contains(element T) bool
	// ContainsAny checks if the set contains any of the specified values.
	ContainsAny(values ...T) bool
	// ContainsAll checks if the set contains all of the specified values.
	ContainsAll(values ...T) bool
	// Intersection returns a new set containing the elements that are common to both the current set and the input set `ts`.
	Intersection(ts Set[T]) Set[T]
	// Union returns a new set containing all the elements that are present in both the current set and the input set `ts`.
	Union(ts Set[T]) Set[T]
	// Difference  returns a new set containing the elements that are present in the current set but not in the input set `ts`.
	Difference(ts Set[T]) Set[T]
	// SymmetricDifference returns a new set containing the elements that are present in either the current set or the input set `ts`, but not in both.
	SymmetricDifference(ts Set[T]) Set[T]
}

func KeySet

func KeySet[M ~map[K]V, K comparable, V any](m M) Set[K]

func NewSet

func NewSet[V comparable](values ...V) Set[V]

func NewXet

func NewXet[I any, O comparable](mapper function.Func[I, O], values ...I) Set[I]

Jump to

Keyboard shortcuts

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