Documentation
¶
Overview ¶
Package godash provides utility functions for searching and manipulating slices in golang. Inspired by the Lodash library in Javascript.
Index ¶
- func FindBy(slice interface{}, fn validator) (interface{}, error)
- func FindIndex(slice interface{}, value interface{}) (int, error)
- func FindIndexBy(slice interface{}, fn validator) (int, error)
- func FindLastBy(slice interface{}, fn validator) (interface{}, error)
- func FindLastIndex(slice interface{}, value interface{}) (int, error)
- func Intersection(slice1 interface{}, slice2 interface{}) (interface{}, error)
- func IntersectionBy(slice1 interface{}, slice2 interface{}, fn mutator) (interface{}, error)
- func Uniq(slice interface{}) (interface{}, error)
- func Without(slice interface{}, values ...interface{}) (interface{}, error)
- func WithoutBy(slice interface{}, fn validator) (interface{}, error)
- func WithoutFloat32(slice []float32, values ...interface{}) ([]float32, error)
- func WithoutInt(slice []int, values ...interface{}) ([]int, error)
- func WithoutInt8(slice []int8, values ...interface{}) ([]int8, error)
- func WithoutString(slice []string, values ...interface{}) ([]string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindBy ¶
func FindBy(slice interface{}, fn validator) (interface{}, error)
FindBy returns the first element of the slice that the provided validator function returns true for. The supplied function must accept an interface{} parameter and return bool. If the validator function does not return true for any values in the slice, nil is returned.
func FindIndex ¶
FindIndex returns the index of the first element in a slice that equals the provided value. If the value is not found in the slice, -1 is returned.
func FindIndexBy ¶
FindIndexBy returns the index of the first element of a slice that the provided validator function returns true for. The supplied function must accept an interface{} parameter and return bool. If the validator function does not return true for any values in the slice, -1 is returned.
func FindLastBy ¶
func FindLastBy(slice interface{}, fn validator) (interface{}, error)
FindLastBy returns the last element of the slice that the provided validator function returns true for. The supplied function must accept an interface{} parameter and return bool. If the validator function does not return true for any values in the slice, nil is returned.
func FindLastIndex ¶
FindLastIndex returns the index of the last element in a slice that equals the provided value. If the value is not found in the slice, -1 is returned.
func Intersection ¶
func Intersection(slice1 interface{}, slice2 interface{}) (interface{}, error)
Intersection creates a slice of unique values that were present in both of the provided slices. The order of the items in the resulting slice is determined by the first given slice. The new slice is returned as an interface{} and may need to have a type assertion applied to it afterwards.
func IntersectionBy ¶
func IntersectionBy(slice1 interface{}, slice2 interface{}, fn mutator) (interface{}, error)
IntersectionBy passes items from two provided slices through a provided mutator function and creates a new slice with items that resulted in common mutated values. The supplied mutator function must accept an interface{} parameter and return interface{} with the value to be compared. The order and values of the items in the resulting slice are determined by the first given slice. The new slice is returned as an interface{} and may need to have a type assertion applied to it afterwards.
func Uniq ¶
func Uniq(slice interface{}) (interface{}, error)
Uniq removes duplicate values from a slice and returns the new slice. The new slice is returned as an interface{} and may need to have a type assertion applied to it afterwards.
func Without ¶
func Without(slice interface{}, values ...interface{}) (interface{}, error)
Without removes values from a slice and returns the new slice. It accepts a slice of any type as the first parameter, followed by a list of parameter values to remove from the slice. The additional values must be of the same type as the provided slice. If using a basic type, such as string or int, it is recommended to use the more specific functions, such as WithoutString or WithoutInt. Otherwise, if using this function directly, the returned result will need to have a type assertion applied.
func WithoutBy ¶
func WithoutBy(slice interface{}, fn validator) (interface{}, error)
WithoutBy removes values from a slice based on output from a provided validator function and returns the new slice. The supplied function must accept an interface{} parameter and return bool. Values for which the validator function returns true will be removed from the slice.
func WithoutFloat32 ¶
WithoutFloat32 removes float32 values from a float32 slice
func WithoutInt ¶
WithoutInt removes int values from an int slice
func WithoutInt8 ¶
WithoutInt8 removes int8 values from an int8 slice
func WithoutString ¶
WithoutString removes string values from a string slice
Types ¶
This section is empty.