Documentation
      ¶
    
    
  
    
  
    Index ¶
- func Compact(arr []interface{}) []interface{}
 - func Flatten(arr []interface{}) []interface{}
 - func Inject(arr []interface{}, initial interface{}, injectFunc InjectFunc) interface{}
 - func Map(arr []interface{}, mapFunc MapFunc) []interface{}
 - func Reject(arr []interface{}, rejectFunc RejectFunc) []interface{}
 - func Select(arr []interface{}, selectFunc SelectFunc) []interface{}
 - func Unique(arr []interface{}) []interface{}
 - type InjectFunc
 - type MapFunc
 - type RejectFunc
 - type SelectFunc
 
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compact ¶
func Compact(arr []interface{}) []interface{}
    Removes nil values from an array.
Example:
var arr = []interface{}{1, 2, 3, 4, nil, 5}
result := Compact(arr)  // [1, 2, 3, 4, 5]
  
        func Flatten ¶
func Flatten(arr []interface{}) []interface{}
    Returns a new array that is one-dimensional flat.
Example:
var arr1 = []interface{}{1, 2, 3, 4}       // [1, 2, 3, 4]
var arr2 = []interface{}{5, 6, 7, arr1}    // [5, 6, 7, [1, 2, 3, 4]]
result := arrayutil.Flatten(arr2)          // [5, 6, 7, 1, 2, 3, 4]
  
        func Inject ¶
func Inject(arr []interface{}, initial interface{}, injectFunc InjectFunc) interface{}
    Combines all elements of array by applying an operation, specified by `InjectFunc`. For each element, the `InjectFunc` is passed a memo value and the element. The result becomes the memo value for the next iteration.
If `nil` is passed to the `initial` memo value, it will use the first element.
Example:
func Sum(memo interface{}, e interface{}) interface{} {
	return memo.(int) + e.(int)
}
var myArray = []interface{}{1, 2, 3, 4}
result := Inject(myArray, nil, Sum)     // result is 10
result := Inject(myArray, 10, Sum)      // result is 20
  
        func Map ¶
func Map(arr []interface{}, mapFunc MapFunc) []interface{}
    Invokes `MapFunc` for each element in the array. Creates a new array containing the values returned by `MapFunc`
Example:
func MyMapFunc(v interface{}) interface{} {
	return v.(int) * 3
}
var myArray = []interface{}{1, 2, 3, 4}
result := arrayutil.Map(myArray, MyMapFunc)  // [3, 6, 9, 12]
  
        func Reject ¶
func Reject(arr []interface{}, rejectFunc RejectFunc) []interface{}
    Invokes `RejectFunc` for each element in the array, deleting elements for which the function returns true. Opposite of Select().
Example:
func Even(v interface{}) bool {
	return v.(int)%2 == 0
}
var myArray = []interface{}{1, 2, 3, 4}
result := Reject(myArray, Even)  // [1, 3]
  
        func Select ¶
func Select(arr []interface{}, selectFunc SelectFunc) []interface{}
    Invokes `SelectFunc` for each element in the array, keeping elements for which the function returns true. Opposite of Reject().
Example:
func Even(v interface{}) bool {
	return v.(int)%2 == 0
}
var myArray = []interface{}{1, 2, 3, 4}
result := Select(myArray, Even)  // [2, 4]
  
        Types ¶
type InjectFunc ¶
type InjectFunc func(interface{}, interface{}) interface{}
    type RejectFunc ¶
type RejectFunc func(interface{}) bool
    type SelectFunc ¶
type SelectFunc func(interface{}) bool