Back to Lo

Mutable Reverse

docs/data/mutable-reverse.md

1.53.0408 B
Original Source

Reverses the slice in place so the first element becomes the last, the second becomes the second-to-last, and so on.

go
import lom "github.com/samber/lo/mutable"

list := []int{0, 1, 2, 3, 4, 5}
lom.Reverse(list)
// list -> []int{5, 4, 3, 2, 1, 0}

With custom types:

go
type Point struct{ X, Y int }
pts := []Point{{0,0}, {1,1}, {2,2}}
lom.Reverse(pts)
// pts -> []Point{{2,2}, {1,1}, {0,0}}