Documentation
¶
Index ¶
- func Contains[T comparable](collection []T, element T) bool
- func EveryBy[T any](collection []T, predicate func(item T) bool) bool
- func Filter[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 GroupBy[T any, U comparable](collection []T, iteratee func(item T) U) map[U][]T
- func Keys[K comparable, V any](in map[K]V) []K
- func Last[T any](collection []T) (T, error)
- func Map[T any, R any](collection []T, iteratee func(item T, index int) R) []R
- func Reduce[T any, R any](collection []T, accumulator func(agg R, item T, index int) R, initial R) R
- func Reject[V any](collection []V, predicate func(item V, index int) bool) []V
- func Sum[T constraints.Float | constraints.Integer | constraints.Complex](collection []T) T
- func Ternary[T any](condition bool, ifOutput, elseOutput T) T
- func TernaryF[T any](condition bool, ifFunc, elseFunc func() T) T
- func Uniq[T comparable](collection []T) []T
- func Values[K comparable, V any](in map[K]V) []V
- type Clonable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
func Contains[T comparable](collection []T, element T) bool
Contains returns true if an element is present in a collection.
func EveryBy ¶
EveryBy returns true if the predicate returns true for all of the elements in the collection or if the collection is empty.
func Filter ¶
Filter iterates over elements of collection, returning an array of all elements predicate returns truthy for. Play: https://go.dev/play/p/Apjg3WeSi7K
func Find ¶
Find search an element in a slice based on a predicate. It returns element and true if element was found.
func GroupBy ¶
func GroupBy[T any, U comparable](collection []T, iteratee func(item T) U) map[U][]T
GroupBy returns an object composed of keys generated from the results of running each element of collection through iteratee. Play: https://go.dev/play/p/XnQBd_v6brd
func Keys ¶
func Keys[K comparable, V any](in map[K]V) []K
Keys creates an array of the map keys. Play: https://go.dev/play/p/Uu11fHASqrU
func Map ¶
Map manipulates a slice and transforms it to a slice of another type. Play: https://go.dev/play/p/OkPcYAhBo0D
func Reduce ¶
func Reduce[T any, R any](collection []T, accumulator func(agg R, item T, index int) R, initial R) R
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. Play: https://go.dev/play/p/R4UHXZNaaUG
func Reject ¶
Reject is the opposite of Filter, this method returns the elements of collection that predicate does not return truthy for. Play: https://go.dev/play/p/YkLMODy1WEL
func Sum ¶
func Sum[T constraints.Float | constraints.Integer | constraints.Complex](collection []T) T
Sum sums the values in a collection. If collection is empty 0 is returned. Play: https://go.dev/play/p/upfeJVqs4Bt
func Uniq ¶
func Uniq[T comparable](collection []T) []T
Uniq returns a duplicate-free version of an array, in which only the first occurrence of each element is kept. The order of result values is determined by the order they occur in the array. Play: https://go.dev/play/p/DTzbeXZ6iEN
func Values ¶
func Values[K comparable, V any](in map[K]V) []V
Values creates an array of the map values. Play: https://go.dev/play/p/nnRTQkzQfF6