Skip to content

Instantly share code, notes, and snippets.

Last active Mar 13, 2019
What would you like to do?
golang > the fastest version of a slice of structs filtering will be a recreation of new slice of structs
// ref.
y := x[:0]
for _, n := range x {
if !=42 {
y = append(y, n)
// If some further sorting should be done, requires Go 1.8+
sort.Slice(y, func(i, j int) bool {
return y[i].ID < y[j].ID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment