Documentation
¶
Index ¶
- func Every[T comparable](collection []T, subset []T) bool
- func Filter[V any](collection []V, predicate func(item V) bool) []V
- func FilterWithIndex[V any](collection []V, predicate func(item V, index int) bool) []V
- func Find[T any](collection []T, predicate func(item T) bool) (T, bool)
- func FlatMap[T any, R any](collection []T, iteratee func(item T) []R) []R
- func FlatMapWithIndex[T any, R any](collection []T, iteratee func(item T, index int) []R) []R
- func FromPtrOr[T any](x *T, fallback T) T
- func HasDuplicates[T comparable](collection []T) bool
- func HasDuplicatesBy[T any, U comparable](collection []T, iteratee func(item T) U) bool
- func Intersect[T comparable, Slice ~[]T](list1 Slice, list2 Slice) Slice
- func Invert[K comparable, V comparable](in map[K]V) map[V]K
- func Map[T any, R any](collection []T, iteratee func(item T) R) []R
- func MapWithError[T any, R any](collection []T, iteratee func(item T) (R, error)) ([]R, error)
- func MapWithIndex[T any, R any](collection []T, iteratee func(item T, index int) R) []R
- func MapWithIndexError[T any, R any](collection []T, iteratee func(item T, index int) (R, error)) ([]R, error)
- func Reduce[T any, R any](collection []T, accumulator func(agg R, item T) R, initial R) R
- func ReduceWithIndex[T any, R any](collection []T, accumulator func(agg R, item T, index int) R, initial R) R
- func Some[T comparable](collection []T, subset []T) bool
- func ToPtr[T any](x T) *T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Every ¶
func Every[T comparable](collection []T, subset []T) bool
Every returns true if all elements of a subset are contained into a collection or if the subset is empty.
func Filter ¶
Filter iterates over elements of collection, returning an array of all elements predicate returns truthy for.
func FilterWithIndex ¶
FilterWithIndex iterates over elements of collection, returning an array of all elements predicate returns truthy for.
func Find ¶
Find search an element in a slice based on a predicate. It returns element and true if element was found.
func FlatMap ¶
FlatMap manipulates a slice and transforms and flattens it to a slice of another type. The transform function can either return a slice or a `nil`, and in the `nil` case no value is added to the final slice.
func FlatMapWithIndex ¶
FlatMapWithIndex manipulates a slice and transforms and flattens it to a slice of another type. The transform function can either return a slice or a `nil`, and in the `nil` case no value is added to the final slice.
func FromPtrOr ¶
func FromPtrOr[T any](x *T, fallback T) T
FromPtrOr returns the pointer value or the fallback value.
func HasDuplicates ¶
func HasDuplicates[T comparable](collection []T) bool
HasDuplicates checks whether the given slice contains duplicate values and returns a boolean result.
func HasDuplicatesBy ¶
func HasDuplicatesBy[T any, U comparable](collection []T, iteratee func(item T) U) bool
HasDuplicatesBy determines whether the provided slice contains duplicate values by examining the return value from the passed function and returns a boolean result.
func Intersect ¶
func Intersect[T comparable, Slice ~[]T](list1 Slice, list2 Slice) Slice
Intersect returns the intersection between two collections.
func Invert ¶
func Invert[K comparable, V comparable](in map[K]V) map[V]K
Invert creates a map composed of the inverted keys and values. If map contains duplicate values, subsequent values overwrite property assignments of previous values. Play: https://go.dev/play/p/rFQ4rak6iA1
func MapWithError ¶
MapWithError manipulates a slice and transforms it to a slice of another type. If iteratee returns an error the function shortcircuits and the error is returned alongside nil.
func MapWithIndex ¶
MapWithIndex manipulates a slice and transforms it to a slice of another type.
func MapWithIndexError ¶
func MapWithIndexError[T any, R any](collection []T, iteratee func(item T, index int) (R, error)) ([]R, error)
MapWithIndexError manipulates a slice and transforms it to a slice of another type. If iteratee returns an error the function shortcircuits and the error is returned alongside nil.
func Reduce ¶
Reduce reduces collection to a value which is the accumulated result of running each element in collection through accumulator, where each successive invocation is supplied the return value of the previous.
func ReduceWithIndex ¶
func ReduceWithIndex[T any, R any](collection []T, accumulator func(agg R, item T, index int) R, initial R) R
ReduceWithIndex reduces collection to a value which is the accumulated result of running each element in collection through accumulator, where each successive invocation is supplied the return value of the previous. The accumulator function receives the index of each element.
func Some ¶
func Some[T comparable](collection []T, subset []T) bool
Some returns true if at least 1 element of a subset is contained into a collection. If the subset is empty Some returns false.
Types ¶
This section is empty.