functional

package
v0.9.10 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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.

Types

type Map

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

func NewMap

func NewMap[MapType Map[KT, VT], KT comparable, VT any]() Map[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]) CollectErrors

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

CollectErrors calls the given function for each key-value pair in the map, then returns a slice of errors collected.

func (Map[KT, VT]) CollectErrorsParallel

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

CollectErrors calls the given function for each key-value pair in the map, then returns a slice of errors collected.

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]) String

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

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

func NewSet

func NewSet[T comparable]() Set[T]

func (Set[T]) Add

func (set Set[T]) Add(v T)

func (Set[T]) Clear

func (set Set[T]) Clear()

func (Set[T]) Contains

func (set Set[T]) Contains(v T) bool

func (Set[T]) IsEmpty

func (set Set[T]) IsEmpty() bool

func (Set[T]) Range

func (set Set[T]) Range(f func(T) bool)

func (Set[T]) RangeAll

func (set Set[T]) RangeAll(f func(T))

func (Set[T]) RangeAllParallel

func (set Set[T]) RangeAllParallel(f func(T))

func (Set[T]) Remove

func (set Set[T]) Remove(v T)

func (Set[T]) Size

func (set Set[T]) Size() int

Jump to

Keyboard shortcuts

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