Documentation ¶
Index ¶
- func All[T comparable](slice []T, f func(T) bool) bool
- func Any[T comparable](slice []T, f func(T) bool) bool
- func Coalesce(input []any) []any
- func Constrain[T comparable](e T, a []T) bool
- func Contains[T comparable](a []T, e T) bool
- func Diff[T comparable](s1, s2 []T) []T
- func Filter[T any](slice []T, f func(T) bool) []T
- func Intersect[T comparable](s1, s2 []T) []T
- func Map[T, U any](slice []T, fn func(T) U) []U
- func Max[T Number](slice []T) T
- func MergeDict[T any](dst map[string]T, src map[string]T)
- func Min[T Number](slice []T) T
- func Reduce[T comparable, U any](slice []T, initial U, reducer func(U, T) U) U
- func Reject[T, U comparable](slice []T, fn func(T) (bool, U)) []U
- func Select[T, U comparable](slice []T, fn func(T) (bool, U)) []U
- func Sum[T Number](slice []T) T
- func Unique[T comparable](slice []T) []T
- type Enumerable
- type Int
- type Number
- type String
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func All ¶
func All[T comparable](slice []T, f func(T) bool) bool
"All" returns true if the given function returns true for all elements of the slice. Supports all comparable types for slice values.
func Any ¶
func Any[T comparable](slice []T, f func(T) bool) bool
"Any" returns true if the given function returns true for any element of the slice. Supports all comparable types as slice values.
func Coalesce ¶
Removes nil values from an array.
Example: var arr = []interface{}{1, 2, 3, nil, 4, 5} result := Compact(arr) // [1, 2, 3, 4, 5]
func Constrain ¶
func Constrain[T comparable](e T, a []T) bool
Whether the element is within the supplied slice's values Actually, it's the same as above ... only with reversed params
func Contains ¶
func Contains[T comparable](a []T, e T) bool
Whether the supplied slice contains element 'e' or not
func Diff ¶
func Diff[T comparable](s1, s2 []T) []T
Diff returns the difference slice from two slices (values in s1 that are not in s2). Returns empty if given slice s1 is nil or empty. naïve implementation: O(n2) complexity
func Filter ¶
Filter filters the values of slice by the given function. Returns empty if given slice is nil or empty.
func Intersect ¶
func Intersect[T comparable](s1, s2 []T) []T
Intersect returns the intersection of two slices. Returns empty if any of the given slices are nil or empty. naïve implementation: O(n2) complexity
func Max ¶
func Max[T Number](slice []T) T
Max get the max value of slice. Returns 0 if slice is nil or empty.
func MergeDict ¶
MergeDict: merges two dictionaries; destination values will get overwritten by those on src
func Min ¶
func Min[T Number](slice []T) T
Min get the min value of slice. Returns 0 if slice is nil or empty.
func Reduce ¶
func Reduce[T comparable, U any](slice []T, initial U, reducer func(U, T) U) U
func Reject ¶
func Reject[T, U comparable](slice []T, fn func(T) (bool, U)) []U
func Select ¶
func Select[T, U comparable](slice []T, fn func(T) (bool, U)) []U
Select / Reject -> filter Supports all comparable types as slice values.
func Unique ¶
func Unique[T comparable](slice []T) []T
Types ¶
type Enumerable ¶
type Enumerable interface { Integer | Float | ~string }