utils

package
v1.12.1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2023 License: Apache-2.0 Imports: 5 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAll deprecated

func AddAll[T any](src types.Collection[T], target types.Collection[T]) int

AddAll adds all elems from src collection into target collection, return number of elems actually added

Deprecated: please use AddAllTo, will be removed in future releases

func AddAllTo added in v1.12.0

func AddAllTo[T any](src types.Collection[T], target types.Collection[T]) int

AddAllTo adds all elems from src collection into target collection, return number of elems actually added

func AddSliceTo

func AddSliceTo[T any](elems []T, col types.Collection[T])

AddSliceTo add all elems from the slice to the collection

func Compute

func Compute[K any, V any](m types.Map[K, V], k K, fn func(v V, found bool) V) V

Compute sets the computed value for the given key by a re-mapping function. Return the computed value.

fn - the re-mapping function: v - the old value or Nil, found - if there's an association of the key

func ComputeIfAbsent

func ComputeIfAbsent[K any, V any](m types.Map[K, V], k K, fn func() V) (V, bool)

ComputeIfAbsent sets the computed value for the given key by a function when there's no association existing. Return the computed value and true if put, or the old value and false if the computation didn't happen.

fn - the function to compute the value

func KeysFrom

func KeysFrom[K any, V any](m types.Map[K, V]) []K

func MultiValuesTo

func MultiValuesTo[K any, V any](src types.Map[K, types.Collection[V]], tgt types.Collection[V]) int

MultiValuesTo adds all values from a multi map to a target collection

func Nil

func Nil[T any]() (v T)

func SliceFrom

func SliceFrom[T any](col types.Collection[T]) []T

SliceFrom creates a new slice from the Collection,

len(slice) = min(size, elemCntFromIterator)
cap(slice) = size

func SliceFromIt

func SliceFromIt[T any](it types.Iterator[T], size int) []T

SliceFromIt creates a new slice from the Iterator,

func SliceProject

func SliceProject[T any, R any](col types.Collection[T], fn func(t T) R) []R

SliceProject creates a new slice from the Collection and projects the elem by given mapping function.

len(slice) = min(size, elemCntFromIterator)
cap(slice) = size

func SliceProjectIt

func SliceProjectIt[T any, R any](it types.Iterator[T], size int, fn func(t T) R) []R

SliceProjectIt creates a new slice from the Iterator and projects the elem by given mapping function.

func Sort added in v1.5.0

func Sort[T any](list types.IndexAccess[T], lessFn types.Less[T])

func SortC added in v1.12.0

func SortC[T types.WithLess[T]](list types.IndexAccess[T])

SortC sorts the index based collection with elements implementing types.WithLess

func SortOrderable added in v1.5.0

func SortOrderable[T constraints.Ordered](list types.IndexAccess[T])

func StringFrom

func StringFrom[T any](b types.Collection[T]) *string

func StringFromf added in v1.5.0

func StringFromf[T any](b types.Collection[T], toStringFn func(elem T) string) *string

func ValuesFrom

func ValuesFrom[K any, V any](m types.Map[K, V]) []V

func ValuesFromMulti

func ValuesFromMulti[K any, V any](m types.Map[K, types.Collection[V]]) []V

func ValuesTo added in v1.12.0

func ValuesTo[K any, V any](src types.Map[K, V], tgt types.Collection[V]) int

Types

This section is empty.

Jump to

Keyboard shortcuts

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