Documentation ¶
Index ¶
- func All[T any](slice []T, predicate func(T) bool) bool
- func Any[T any](slice []T, predicate func(T) bool) bool
- func Associate[T any, K comparable, V any](slice []T, transform func(T) (K, V)) map[K]V
- func Contains[T comparable](slice []T, target T) bool
- func ContainsKey[K comparable, V any](hashMap map[K]V, target K) bool
- func Drop[T any](slice []T, index int) []T
- func Filter[T any](slice []T, predicate func(T) bool) []T
- func FilterIndexed[T any](slice []T, predicate func(int, T) bool) []T
- func FilterKeys[K comparable, V any](hashMap map[K]V, predicate func(K) bool) map[K]V
- func First[T any](slice []T, predicate func(T) bool) (T, error)
- func FirstOrDefault[T any](slice []T, defaultValue T, predicate func(T) bool) T
- func FlatMap[K comparable, V, R any](hashMap map[K]V, transform func(K, V) R) []R
- func Flatten[T any](slices [][]T) []T
- func Fold[T any, R any](slice []T, initial R, operation func(T, R) R) R
- func FoldIndexed[T any, R any](slice []T, initial R, operation func(int, T, R) R) R
- func FoldRight[T any, R any](slice []T, initial R, operation func(T, R) R) R
- func FoldRightIndexed[T any, R any](slice []T, initial R, operation func(int, T, R) R) R
- func ForEach[T any](slice []T, operation func(T))
- func ForEachEntry[K comparable, V any](hashMap map[K]V, operation func(K, V))
- func ForEachIndexed[T any](slice []T, operation func(int, T))
- func GetOrDefault[K comparable, V any](hashMap map[K]V, key K, defaultVal V) V
- func GroupBy[T any, K comparable](slice []T, selector func(T) K) map[K][]T
- func IndexOf[T comparable](slice []T, target T) int
- func Keys[K comparable, V any](hashMap map[K]V) []K
- func Map[T any, R any](slice []T, transform func(T) R) []R
- func MapIndexed[T any, R any](slice []T, transform func(int, T) R) []R
- func MaxOf[T constraints.Ordered](slice []T) (T, error)
- func MaxOfBy[T any](slice []T, comparer func(T, T) int) (T, error)
- func MinOf[T constraints.Ordered](slice []T) (T, error)
- func MinOfBy[T any](slice []T, comparer func(T, T) int) (T, error)
- func Partition[T any](slice []T, predicate func(T) bool) ([]T, []T)
- func Reversed[T any](slice []T) []T
- func SubList[T any](slice []T, from, to int) []T
- func Values[K comparable, V any](hashMap map[K]V) []V
- type Pair
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Associate ¶
func Associate[T any, K comparable, V any](slice []T, transform func(T) (K, V)) map[K]V
Returns a map generated from the given slice, using the given transform
func Contains ¶
func Contains[T comparable](slice []T, target T) bool
Returns whether the given slice contains the given target value
func ContainsKey ¶
func ContainsKey[K comparable, V any](hashMap map[K]V, target K) bool
Returns whether the map contains the key
func Drop ¶
Drops the value from the given slice at index and returns. The original slice remains unchanged.
func FilterIndexed ¶
Filters the slice based on the given predicate The predicate also considers index of each element
func FilterKeys ¶
func FilterKeys[K comparable, V any](hashMap map[K]V, predicate func(K) bool) map[K]V
Filter keys based on the given predicate
func First ¶
Returns the first value the satisfies the given predicate. Raises error if there is no such element
func FirstOrDefault ¶
Returns the first value the satisfies the given predicate. If no such element is there then returns defaultValue
func FlatMap ¶
func FlatMap[K comparable, V, R any](hashMap map[K]V, transform func(K, V) R) []R
Maps the map into a slice based on the given transform
func Fold ¶
Accumulates value starting with the given initial by performing operation on the slice from left to right
func FoldIndexed ¶
Accumulates value starting with the given initial by performing operation on the slice from left to right The operation also considers index of each element
func FoldRight ¶
Accumulates value starting with the given initial by performing operation on the slice from right to left
func FoldRightIndexed ¶
Accumulates value starting with the given initial by performing operation on the slice from right to left The operation also considers index of each element
func ForEach ¶
func ForEach[T any](slice []T, operation func(T))
Performs the given operation for each of element in the slice
func ForEachEntry ¶
func ForEachEntry[K comparable, V any](hashMap map[K]V, operation func(K, V))
Runs operation on each entry of the map
func ForEachIndexed ¶
Performs the given operation for each of element in the slice The operation also considers index of each element
func GetOrDefault ¶
func GetOrDefault[K comparable, V any](hashMap map[K]V, key K, defaultVal V) V
Get the value corresponding to the key, returns default value if the key is not there.
func GroupBy ¶
func GroupBy[T any, K comparable](slice []T, selector func(T) K) map[K][]T
func IndexOf ¶
func IndexOf[T comparable](slice []T, target T) int
Returns the index of the target element inside the slice. Returns -1 if that element does not exist.
func Map ¶
Applies the transform function on each element of the slice and returns a slice of the transformed value
func MapIndexed ¶
Applies the transform function on each element of the slice and returns a slice of the transformed value The transform also considers index of each element
func MaxOf ¶
func MaxOf[T constraints.Ordered](slice []T) (T, error)
Returns maximum of the slice, error if empty
func MaxOfBy ¶
Returns maximum of slice using the comparer function. If a > b then comparer(a, b) > 0
func MinOf ¶
func MinOf[T constraints.Ordered](slice []T) (T, error)
Returns minimum of the slice, error if empty
func MinOfBy ¶
Returns minimum of slice using the comparer function. If a > b then comparer(a, b) > 0
func Partition ¶
Partitions the slice based on the predicate. The left slice contains the elements that satisfies predicate and the right one contains the elements that does not.