Documentation ¶
Index ¶
- func AllMatch[TSlice ~[]T, T any](slice TSlice, predicate func(T) bool) bool
- func AnyMatch[TSlice ~[]T, T any](slice TSlice, predicate func(T) bool) bool
- func Contains[TSlice ~[]T, T comparable](slice TSlice, find T) bool
- func Difference[Map ~map[K]V, K comparable, V any](left, right Map) Map
- func Filter[TSlice ~[]T, T any](slice TSlice, predicate func(T) bool) TSlice
- func FirstMatch[TSlice ~[]T, T any](slice TSlice, predicate func(T) bool) T
- func GroupBy[TSlice ~[]T, T any, K comparable, V any](slice TSlice, keySelector func(T) K, valSelector func(T) V) map[K][]V
- func IndexOf[TSlice ~[]T, T comparable](slice TSlice, find T) int
- func Intersect[Map ~map[K]V, K comparable, V any](left, right Map) Map
- func Keys[Map ~map[K]V, K comparable, V any](m Map) []K
- func LastMatch[TSlice ~[]T, T any](slice TSlice, predicate func(T) bool) T
- func Map[TSlice ~[]T, T any, R any](slice TSlice, fn func(T) R) []R
- func Reduce[TSlice ~[]T, T any, R any](slice TSlice, fn func(acc R, elem T) R, acc R) R
- func SliceDifference[T comparable](a, b []T) []T
- func SliceEqual[T comparable](a, b []T) bool
- func SliceIntersection[T comparable](a, b []T) []T
- func SliceUnion[T comparable](a, b []T) []T
- func ToMap[TSlice ~[]T, T any, K comparable, V any](slice TSlice, keySelector func(T) K, valSelector func(T) V) map[K]V
- func ToSet[TSlice ~[]T, T any, K comparable](slice TSlice, keySelector func(T) K) map[K]struct{}
- func Union[Map ~map[K]V, K comparable, V any](left, right Map) Map
- func UnionInPlace[Map ~map[K]V, K comparable, V any](left, right Map) Map
- func Uniq[TSlice ~[]T, T any, K comparable](slice TSlice, keySelector func(T) K) (uniqSlice TSlice)
- func Values[Map ~map[K]V, K comparable, V any](m Map) []V
- type Set
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
func Contains[TSlice ~[]T, T comparable](slice TSlice, find T) bool
Contains returns true if find appears in slice
func Difference ¶
func Difference[Map ~map[K]V, K comparable, V any](left, right Map) Map
Difference returns a new map of key/value pairs that only appear in left.
func Filter ¶
Filter returns a new slice consisting of all elements that pass the predicate function
func FirstMatch ¶
FirstMatch returns the first element that passes the predicate function. If no element is found the zero value of the type will be returned.
func GroupBy ¶
func GroupBy[TSlice ~[]T, T any, K comparable, V any](slice TSlice, keySelector func(T) K, valSelector func(T) V) map[K][]V
GroupBy returns a map that is keyed by keySelector and contains a slice of elements returned by valSelector
func IndexOf ¶
func IndexOf[TSlice ~[]T, T comparable](slice TSlice, find T) int
IndexOf returns the index of find if it appears in slice. If find is not in slice, -1 will be returned.
func Intersect ¶
func Intersect[Map ~map[K]V, K comparable, V any](left, right Map) Map
Intersect returns a new map of key/value pairs where the key exists in both left and right. The value from right will be used in the return map.
func Keys ¶
func Keys[Map ~map[K]V, K comparable, V any](m Map) []K
Keys returns a slice of all keys in m
func LastMatch ¶
LastMatch returns the last element that passes the predicate function. If no element is found the zero value of the type will be returned.
func Map ¶
Map returns a new slice where each element is the result of fn for the corresponding element in the original slice
func SliceDifference ¶
func SliceDifference[T comparable](a, b []T) []T
SliceDifference Difference of two slices(A-B). Slices do not need to be unique. Order not guaranteed.
@param a []T @param b []T @return []T @author kevineluo @update 2023-03-01 04:41:53
func SliceEqual ¶
func SliceEqual[T comparable](a, b []T) bool
SliceEqual judge if two slice is equal(unique element)
@param a []T @param b []T @return bool @author kevineluo @update 2023-03-01 04:46:22
func SliceIntersection ¶
func SliceIntersection[T comparable](a, b []T) []T
SliceIntersection Intersection of two slices, The provided slices do not need to be unique. Order not guaranteed.
@param a []T @param b []T @return []T @author kevineluo @update 2023-03-01 04:41:58
func SliceUnion ¶
func SliceUnion[T comparable](a, b []T) []T
SliceUnion Union two slices, The provided slices do not need to be unique. Order not guaranteed.
@param a []T @param b []T @return []T @author kevineluo @update 2023-03-01 04:42:00
func ToMap ¶
func ToMap[TSlice ~[]T, T any, K comparable, V any](slice TSlice, keySelector func(T) K, valSelector func(T) V) map[K]V
ToMap return a map that is keyed keySelector and has the value of valSelector for each element in slice. If multiple elements return the same key the element that appears later in slice will be chosen.
func ToSet ¶
func ToSet[TSlice ~[]T, T any, K comparable](slice TSlice, keySelector func(T) K) map[K]struct{}
ToSet returns a map keyed by keySelector and contains a value of an empty struct
func Union ¶
func Union[Map ~map[K]V, K comparable, V any](left, right Map) Map
Union returns a new map of all key/value pairs in left and right. If a key exists in both left and right the value in right will appear in the resultant map.
func UnionInPlace ¶
func UnionInPlace[Map ~map[K]V, K comparable, V any](left, right Map) Map
UnionInPlace modifies left to include key/value pairs in right. If a key exists in both left and right the value in right will be used.
func Uniq ¶
func Uniq[TSlice ~[]T, T any, K comparable](slice TSlice, keySelector func(T) K) (uniqSlice TSlice)
Uniq returns a new slice that uniques in values
func Values ¶
func Values[Map ~map[K]V, K comparable, V any](m Map) []V
Values returns a slice of all values in m
Types ¶
type Set ¶
type Set[T comparable] map[T]struct{}
Set A collection of unique comparable items. Uses a map with only true values to accomplish set functionality.
@author kevineluo @update 2023-03-01 03:52:15
func MapSliceToSet ¶
func MapSliceToSet[S any, T comparable](s []S, f func(s S) T) Set[T]
MapSliceToSet Map a slice to a set using a function f
@param s []S @param f func(s S) T @return Set @author kevineluo @update 2023-03-01 04:42:04
func NewSet ¶
func NewSet[T comparable](size int) Set[T]
NewSet Create a new empty set with the specified initial size.
@param size int @return Set @author kevineluo @update 2023-03-01 03:52:21
func SliceToSet ¶
func SliceToSet[T comparable](s []T) Set[T]
SliceToSet Create a Set from a slice.
@param s []T @return Set @author kevineluo @update 2023-03-01 04:42:55
func (Set[T]) Add ¶
func (s Set[T]) Add(key T)
Add Add a new key to the set
@param s Set[T] @return Add @author kevineluo @update 2023-03-01 03:52:26
func (Set[T]) Contains ¶
Contains Check if Set s contains key
@param s Set[T] @return Contains @author kevineluo @update 2023-03-01 03:52:29
func (Set[T]) Difference ¶
Difference A difference B NOTE: A-B != B-A
@param a Set[T] @return Difference @author kevineluo @update 2023-03-01 03:52:42
func (Set[T]) Equals ¶
Equals A == B (all elements of A are in B and vice versa)
@param a Set[T] @return Equals @author kevineluo @update 2023-03-01 04:43:01
func (Set[T]) Intersection ¶
Intersection A intersect B
@param s Set[T] @return Intersection @author kevineluo @update 2023-03-01 03:54:59
func (Set[T]) Remove ¶
func (s Set[T]) Remove(key T)
Remove Remove a key from the set. If the key is not in the set then noop
@param s Set[T] @return Remove @author kevineluo @update 2023-03-01 03:52:28