Documentation ¶
Index ¶
- func FilterNilValues[K comparable, V any](S map[K]*V) map[K]*V
- func KeyOfDuplicate[K, V comparable](S map[K]V) (K, bool)
- func KeyOfDuplicateFunc[K comparable, V uc.Equaler[V]](S map[K]V) (K, bool)
- func MapFilter[K comparable, V any](S map[K]V, filter PredicateFilter[K, V]) map[K]V
- func RemoveDuplicates[K comparable, V comparable](S map[K]V) map[K]V
- func RemoveDuplicatesFunc[K comparable, V uc.Equaler[V]](S map[K]V) map[K]V
- func SFSeparate[K comparable, V any](S map[K]V, filter PredicateFilter[K, V]) (map[K]V, map[K]V)
- func SFSeparateEarly[K comparable, V any](S map[K]V, filter PredicateFilter[K, V]) (map[K]V, bool)
- type PredicateFilter
- func Intersect[K comparable, V any](funcs ...PredicateFilter[K, V]) PredicateFilter[K, V]
- func ParallelIntersect[K comparable, V any](funcs ...PredicateFilter[K, V]) PredicateFilter[K, V]
- func ParallelUnion[K comparable, V any](funcs ...PredicateFilter[K, V]) PredicateFilter[K, V]
- func Union[K comparable, V any](funcs ...PredicateFilter[K, V]) PredicateFilter[K, V]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FilterNilValues ¶ added in v0.2.39
func FilterNilValues[K comparable, V any](S map[K]*V) map[K]*V
FilterNilValues is a function that iterates over the map and removes elements whose value is nil.
Parameters:
- S: map of elements.
Returns:
- map[K]*V: map of elements that satisfy the filter function.
Behaviors:
- If S is empty, it returns a non-nil empty map.
func KeyOfDuplicate ¶ added in v0.2.39
func KeyOfDuplicate[K, V comparable](S map[K]V) (K, bool)
KeyOfDuplicate returns the index of the first duplicate element in the map.
Parameters:
- S: map of elements.
Returns:
- K: key of the first duplicate element or a zero value if there are no duplicates.
- bool: true if there are duplicates, otherwise false.
func KeyOfDuplicateFunc ¶ added in v0.2.39
func KeyOfDuplicateFunc[K comparable, V uc.Equaler[V]](S map[K]V) (K, bool)
KeyOfDuplicateFunc returns the index of the first duplicate element in the map.
Parameters:
- S: map of elements.
Returns:
- K: key of the first duplicate element or a zero value if there are no duplicates.
- bool: true if there are duplicates, otherwise false.
func MapFilter ¶
func MapFilter[K comparable, V any](S map[K]V, filter PredicateFilter[K, V]) map[K]V
MapFilter is a function that iterates over the map and applies the filter function to each element. The returned map contains the elements that satisfy the filter function.
Parameters:
- S: map of elements.
- filter: function that takes an element and returns a bool.
Returns:
- map[K]V: map of elements that satisfy the filter function.
Behaviors:
- An element is said to satisfy the filter function if the function returns true for that element.
- If S is empty, it returns a non-nil empty map.
- If filter is nil, it returns S as is
func RemoveDuplicates ¶ added in v0.2.39
func RemoveDuplicates[K comparable, V comparable](S map[K]V) map[K]V
RemoveDuplicates removes duplicate elements from the map.
Parameters:
- S: map of elements.
Returns:
- map[K]V: map of elements with duplicates removed.
Behavior:
- The function preserves the order of the elements in the map.
- If there are multiple duplicates of an element, only the first occurrence is kept.
- If there are less than two elements in the map, the function returns the original map.
func RemoveDuplicatesFunc ¶ added in v0.2.39
func RemoveDuplicatesFunc[K comparable, V uc.Equaler[V]](S map[K]V) map[K]V
RemoveDuplicatesFunc removes duplicate elements from the map.
Parameters:
- S: map of elements.
- equals: function that takes two elements and returns a bool.
Returns:
- map[K]V: map of elements with duplicates removed.
Behavior:
- The function preserves the order of the elements in the map.
- If there are multiple duplicates of an element, only the first occurrence is kept.
- If there are less than two elements in the map, the function returns the original map.
func SFSeparate ¶ added in v0.2.39
func SFSeparate[K comparable, V any](S map[K]V, filter PredicateFilter[K, V]) (map[K]V, map[K]V)
SFSeparate is a function that iterates over the map and applies the filter function to each element. The returned slices contain the elements that satisfy and do not satisfy the filter function.
Parameters:
- S: map of elements.
- filter: function that takes an element and returns a bool.
Returns:
- map[K]V: map of elements that satisfy the filter function.
- map[K]V: map of elements that do not satisfy the filter function.
Behavior:
- If S is empty, the function returns two empty slices.
func SFSeparateEarly ¶ added in v0.2.39
func SFSeparateEarly[K comparable, V any](S map[K]V, filter PredicateFilter[K, V]) (map[K]V, bool)
SFSeparateEarly is a variant of SFSeparate that returns all successful elements. If there are none, it returns the original map and false.
Parameters:
- S: map of elements.
- filter: function that takes an element and returns a bool.
Returns:
- map[K]V: map of elements that satisfy the filter function or the original map.
- bool: true if there are successful elements, otherwise false.
Behavior:
- If S is empty, the function returns an empty map and true.
Types ¶
type PredicateFilter ¶
type PredicateFilter[K comparable, V any] func(K, V) bool
PredicateFilter is a type that defines a map filter function.
Parameters:
- K: The type of the elements in the map.
Returns:
- bool: True if the element satisfies the filter function, otherwise false.
func Intersect ¶
func Intersect[K comparable, V any](funcs ...PredicateFilter[K, V]) PredicateFilter[K, V]
Intersect returns a PredicateFilter function that checks if an element satisfies all the PredicateFilter functions in funcs.
Parameters:
- funcs: A map of PredicateFilter functions.
Returns:
- PredicateFilter: A PredicateFilter function that checks if a element satisfies all the PredicateFilter functions in funcs.
Behaviors:
- It returns false as soon as it finds a function in funcs that the element does not satisfy.
- If no functions are provided, it returns a function that always returns true.
func ParallelIntersect ¶ added in v0.2.39
func ParallelIntersect[K comparable, V any](funcs ...PredicateFilter[K, V]) PredicateFilter[K, V]
ParallelIntersect returns a PredicateFilter function that checks if an element satisfies all the PredicateFilter functions in funcs. It runs the PredicateFilter functions in parallel and returns false as soon as it finds a function in funcs that the element does not satisfy.
Parameters:
- funcs: A map of PredicateFilter functions.
Returns:
- PredicateFilter: A PredicateFilter function that checks if a element satisfies all the PredicateFilter functions in funcs.
Behaviors:
- It returns false as soon as it finds a function in funcs that the element does not satisfy.
- If no functions are provided, it returns a function that always returns true.
func ParallelUnion ¶ added in v0.2.39
func ParallelUnion[K comparable, V any](funcs ...PredicateFilter[K, V]) PredicateFilter[K, V]
ParallelUnion returns a PredicateFilter function that checks if an element satisfies at least one of the PredicateFilter functions in funcs. It runs the PredicateFilter functions in parallel and returns true as soon as it finds a function in funcs that the element satisfies.
Parameters:
- funcs: A map of PredicateFilter functions.
Returns:
- PredicateFilter: A PredicateFilter function that checks if a element satisfies at least one of the PredicateFilter functions in funcs.
Behaviors:
- It returns true as soon as it finds a function in funcs that the element satisfies.
- If no functions are provided, it returns a function that always returns false.
func Union ¶
func Union[K comparable, V any](funcs ...PredicateFilter[K, V]) PredicateFilter[K, V]
Union returns a PredicateFilter function that checks if an element satisfies at least one of the PredicateFilter functions in funcs. It returns true as soon as it finds a function in funcs that the element satisfies.
Parameters:
- funcs: A map of PredicateFilter functions.
Returns:
- PredicateFilter: A PredicateFilter function that checks if a element satisfies at least one of the PredicateFilter functions in funcs.
Behaviors:
- It returns true as soon as it finds a function in funcs that the element satisfies.
- If no functions are provided, it returns a function that always returns false.