Files
sablier/pkg/arrays/remove_elements.go
Alexis Couvreur dfb9bacf59 feat(providers): add provider.auto-stop-on-startup argument (#346)
This feature adds the capability to stop unregistered running instances upon startup.

Previously, you had to stop running instances manually or issue an initial request that will shut down instances afterwards.

With this change, all discovered instances will be shutdown. They need to be registered using labels. E.g.: sablier.enable=true

Fixes #153
2024-10-01 17:30:14 -07:00

22 lines
732 B
Go

package arrays
// RemoveElements returns a new slice containing all elements from `allElements` that are not in `elementsToRemove`
func RemoveElements(allElements, elementsToRemove []string) []string {
// Create a map to store elements to remove for quick lookup
removeMap := make(map[string]struct{}, len(elementsToRemove))
for _, elem := range elementsToRemove {
removeMap[elem] = struct{}{}
}
// Create a slice to store the result
result := make([]string, 0, len(allElements)) // Preallocate memory based on the size of allElements
for _, elem := range allElements {
// Check if the element is not in the removeMap
if _, found := removeMap[elem]; !found {
result = append(result, elem)
}
}
return result
}