The array_utils.go
file in the utils
package offers a variety of functions to assist with array operations in Go, providing functionality for element removal, existence checks, filtering, and type conversion.
Removes elements from the toRemove
array that are not present in the source
array.
result := RemoveElementsNotInSource(sourceArray, toRemoveArray)
Parameter | Type | Description |
---|---|---|
source | []T |
The source array to compare against. |
toRemove | []T |
The array containing elements to be removed if not found in the source. |
return value | []T |
An array containing elements not present in the source. |
Determines if any element in targetSlice
is present in contentSlice
.
found := ArrayContainsAny(contentSlice, targetSlice)
Parameter | Type | Description |
---|---|---|
contentSlice | []string |
The array to search within. |
targetSlice | []string |
The array containing target elements to find. |
return value | bool |
true if any target element is found, otherwise false . |
Filters an array based on a provided condition function.
filtered := FilterArray(array, conditionFunc)
Parameter | Type | Description |
---|---|---|
arr | []T |
The array to be filtered. |
condition | func(interface{}, int) bool |
The function used to determine if an element should be included. |
return value | []interface{} |
An array containing elements that meet the condition. |
The subsequent functions (ConvertToInterfaceArray
, ConvertToIntArray
, ConvertToUintArray
, etc.) follow a similar pattern, converting arrays to different types based on the function's purpose, with their usage and reference details structured similarly to the above examples.