functional

package
v0.0.0-...-64e30f5 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FirstValueOf

func FirstValueOf[KT comparable, VT any](m map[KT]VT) (_ VT, ok bool)

func ForEachKV

func ForEachKV[K comparable, V any](obj map[K]V, do func(K, V))

func ForEachKey

func ForEachKey[K comparable, V any](obj map[K]V, do func(K))

func ForEachValue

func ForEachValue[K comparable, V any](obj map[K]V, do func(V))

func MapFind

func MapFind[KT comparable, VT, CT any](m Map[KT, VT], criteria func(VT) (CT, bool)) (_ CT)

MapFind iterates over the map and returns the first value that satisfies the given criteria. The iteration is stopped once a value is found. If no value satisfies the criteria, the function returns the zero value of CT.

The criteria function takes a value of type VT and returns a value of type CT and a boolean indicating whether the value satisfies the criteria. The boolean value is used to determine whether the iteration should be stopped.

The function is safe for concurrent use.

func ParallelForEach

func ParallelForEach[T any](obj []T, do func(T))

func ParallelForEachKV

func ParallelForEachKV[K comparable, V any](obj map[K]V, do func(K, V))

func ParallelForEachKey

func ParallelForEachKey[K comparable, V any](obj map[K]V, do func(K))

func ParallelForEachValue

func ParallelForEachValue[K comparable, V any](obj map[K]V, do func(V))

Types

type Map

type Map[KT comparable, VT any] struct {
	*xsync.MapOf[KT, VT]
}

func NewMapFrom

func NewMapFrom[KT comparable, VT any](m map[KT]VT) (res Map[KT, VT])

func NewMapOf

func NewMapOf[KT comparable, VT any](options ...func(*xsync.MapConfig)) Map[KT, VT]

func (Map[KT, VT]) Has

func (m Map[KT, VT]) Has(k KT) bool

func (Map[KT, VT]) MergeFrom

func (m Map[KT, VT]) MergeFrom(other Map[KT, VT]) Map[KT, VT]

MergeFrom merges the contents of another Map into this one, ignoring duplicated keys.

Parameters:

other: Map of values to add from

Returns:

Map of duplicated keys-value pairs

func (Map[KT, VT]) RangeAll

func (m Map[KT, VT]) RangeAll(do func(k KT, v VT))

RangeAll calls the given function for each key-value pair in the map.

Parameters:

do: function to call for each key-value pair

Returns:

nothing

func (Map[KT, VT]) RangeAllParallel

func (m Map[KT, VT]) RangeAllParallel(do func(k KT, v VT))

RangeAllParallel calls the given function for each key-value pair in the map, in parallel. The map is not safe for modification from within the function.

Parameters:

do: function to call for each key-value pair

Returns:

nothing

func (Map[KT, VT]) RemoveAll

func (m Map[KT, VT]) RemoveAll(criteria func(VT) bool)

RemoveAll removes all key-value pairs from the map where the value matches the given criteria.

Parameters:

criteria: function to determine whether a value should be removed

Returns:

nothing

func (Map[KT, VT]) String

func (m Map[KT, VT]) String() string

func (Map[KT, VT]) UnmarshalFromYAML

func (m Map[KT, VT]) UnmarshalFromYAML(data []byte) E.NestedError

UnmarshalFromYAML unmarshals a yaml byte slice into the map.

It overwrites all existing key-value pairs in the map.

Parameters:

data: yaml byte slice to unmarshal

Returns:

error: if the unmarshaling fails

type Slice

type Slice[T any] struct {
	// contains filtered or unexported fields
}

func NewSlice

func NewSlice[T any]() *Slice[T]

func NewSliceFrom

func NewSliceFrom[T any](s []T) *Slice[T]

func NewSliceN

func NewSliceN[T any](n int) *Slice[T]

func (*Slice[T]) Add

func (s *Slice[T]) Add(e T) *Slice[T]

func (*Slice[T]) AddRange

func (s *Slice[T]) AddRange(other *Slice[T]) *Slice[T]

func (*Slice[T]) Empty

func (s *Slice[T]) Empty() bool

func (*Slice[T]) Filter

func (s *Slice[T]) Filter(f func(T) bool) *Slice[T]

func (*Slice[T]) ForEach

func (s *Slice[T]) ForEach(do func(T))

func (*Slice[T]) Get

func (s *Slice[T]) Get(i int) T

func (*Slice[T]) Iterator

func (s *Slice[T]) Iterator() []T

func (*Slice[T]) Map

func (s *Slice[T]) Map(m func(T) T) *Slice[T]

func (*Slice[T]) NotEmpty

func (s *Slice[T]) NotEmpty() bool

func (*Slice[T]) Pop

func (s *Slice[T]) Pop() T

func (*Slice[T]) Remove

func (s *Slice[T]) Remove(criteria func(T) bool)

func (*Slice[T]) SafeAdd

func (s *Slice[T]) SafeAdd(e T) *Slice[T]

func (*Slice[T]) SafeAddRange

func (s *Slice[T]) SafeAddRange(other *Slice[T]) *Slice[T]

func (*Slice[T]) SafePop

func (s *Slice[T]) SafePop() T

func (*Slice[T]) SafeRemove

func (s *Slice[T]) SafeRemove(criteria func(T) bool)

func (*Slice[T]) Set

func (s *Slice[T]) Set(i int, v T)

func (*Slice[T]) Size

func (s *Slice[T]) Size() int

func (*Slice[T]) String

func (s *Slice[T]) String() string

Jump to

Keyboard shortcuts

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