mutable.Filter duplicates an element
Author: FGasperCreated Mar 8, 2026Updated Mar 30, 2026
https://goplay.tools/snippet/n4gxxXL3Tge
package main
import (
"fmt"
"github.com/samber/lo/mutable"
)
type el struct {
Key string
Val any
}
func main() {
doc := []el{
{"foo", 234},
{"bar", 345},
{"baz", 111},
}
mutable.Filter(
doc,
func(e el) bool {
return e.Key != "bar"
},
)
fmt.Printf("Hello, World! %+v", doc)
}outputs:
Hello, World! [{Key:foo Val:234} {Key:baz Val:111} {Key:baz Val:111}]Note the duplicated baz.
Source: samber/lo