Skip to content

Commit

Permalink
Our reverse function is better
Browse files Browse the repository at this point in the history
  • Loading branch information
Racer159 committed Sep 19, 2023
1 parent b6ea9c0 commit 85f5e09
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/pkg/packager/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ func (p *Packager) Remove() (err error) {
}
}

slices.Reverse(deployedPackage.DeployedComponents)
for _, c := range deployedPackage.DeployedComponents {
for _, c := range helpers.Reverse(deployedPackage.DeployedComponents) {
// Only remove the component if it was requested or if we are removing the whole package
if partialRemove && !slices.Contains(requestedComponents, c.Name) {
continue
Expand Down Expand Up @@ -177,8 +176,7 @@ func (p *Packager) removeComponent(deployedPackage types.DeployedPackage, deploy
return deployedPackage, fmt.Errorf("unable to run the before action for component (%s): %w", c.Name, err)
}

slices.Reverse(deployedComponent.InstalledCharts)
for _, chart := range deployedComponent.InstalledCharts {
for _, chart := range helpers.Reverse(deployedComponent.InstalledCharts) {
spinner.Updatef("Uninstalling chart '%s' from the '%s' component", chart.ChartName, deployedComponent.Name)

helmCfg := helm.Helm{}
Expand Down
8 changes: 8 additions & 0 deletions src/pkg/utils/helpers/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ func Unique[T comparable](s []T) (r []T) {
return r
}

// Reverse returns a new slice with the elements in reverse order.
func Reverse[T any](s []T) (r []T) {
for i := len(s) - 1; i >= 0; i-- {
r = append(r, s[i])
}
return r
}

// Filter returns a new slice with only the elements that pass the test.
func Filter[T any](ss []T, test func(T) bool) (r []T) {
for _, s := range ss {
Expand Down

0 comments on commit 85f5e09

Please sign in to comment.