Created
January 22, 2021 12:38
-
-
Save kamal-github/25b31c363e667ef0bcc62062b3927b19 to your computer and use it in GitHub Desktop.
Remove first element from slice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://play.golang.org/p/7oTksbq9ioW | |
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
removeOne([]Conn{Conn{i: 100}, Conn{i: 200}, Conn{i: 300}, Conn{i: 400}, Conn{i: 500}}) | |
} | |
type Conn struct { | |
i int | |
} | |
func removeOne(freeConn []Conn) { | |
for i := 0; i < len(freeConn); i++ { | |
last := len(freeConn) - 1 | |
freeConn[i] = freeConn[last] | |
freeConn[last] = Conn{} | |
freeConn = freeConn[:last] | |
fmt.Println("freeConn after i ", freeConn, i) | |
i-- | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment